Skip to content

Commit

Permalink
v2.1 Bugfix of issue#75 (#77)
Browse files Browse the repository at this point in the history
* Fix bug in dynamic HTTPRouterHandler switching to prevent StackOverflow.

* Fix bug in dynamic HTTPRouterHandler switching to prevent StackOverflow.
  • Loading branch information
mafei6827 authored Apr 16, 2024
1 parent 5595e79 commit a82c5a2
Show file tree
Hide file tree
Showing 82 changed files with 228 additions and 421 deletions.
2 changes: 1 addition & 1 deletion base-cluster/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<parent>
<artifactId>bifromq-parent</artifactId>
<groupId>com.baidu.bifromq</groupId>
<version>2.1.2</version>
<version>2.1.3-SNAPSHOT</version>
</parent>

<artifactId>base-cluster</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion base-crdt/base-crdt-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<parent>
<groupId>com.baidu.bifromq</groupId>
<artifactId>base-crdt</artifactId>
<version>2.1.2</version>
<version>2.1.3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion base-crdt/base-crdt-store/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>com.baidu.bifromq</groupId>
<artifactId>base-crdt</artifactId>
<version>2.1.2</version>
<version>2.1.3-SNAPSHOT</version>
</parent>

<artifactId>base-crdt-store</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion base-crdt/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>com.baidu.bifromq</groupId>
<artifactId>bifromq-parent</artifactId>
<version>2.1.2</version>
<version>2.1.3-SNAPSHOT</version>
</parent>
<packaging>pom</packaging>

Expand Down
2 changes: 1 addition & 1 deletion base-env/base-env-provider-spi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>com.baidu.bifromq</groupId>
<artifactId>base-env</artifactId>
<version>2.1.2</version>
<version>2.1.3-SNAPSHOT</version>
</parent>

<artifactId>base-env-provider-spi</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion base-env/base-env-provider/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>com.baidu.bifromq</groupId>
<artifactId>base-env</artifactId>
<version>2.1.2</version>
<version>2.1.3-SNAPSHOT</version>
</parent>

<artifactId>base-env-provider</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion base-env/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>com.baidu.bifromq</groupId>
<artifactId>bifromq-parent</artifactId>
<version>2.1.2</version>
<version>2.1.3-SNAPSHOT</version>
</parent>

<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion base-hlc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>com.baidu.bifromq</groupId>
<artifactId>bifromq-parent</artifactId>
<version>2.1.2</version>
<version>2.1.3-SNAPSHOT</version>
</parent>

<artifactId>base-hlc</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion base-hookloader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>com.baidu.bifromq</groupId>
<artifactId>bifromq-parent</artifactId>
<version>2.1.2</version>
<version>2.1.3-SNAPSHOT</version>
</parent>

<artifactId>base-hookloader</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion base-kv/base-kv-local-engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>com.baidu.bifromq</groupId>
<artifactId>base-kv</artifactId>
<version>2.1.2</version>
<version>2.1.3-SNAPSHOT</version>
</parent>

<artifactId>base-kv-local-engine</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion base-kv/base-kv-raft-type/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>com.baidu.bifromq</groupId>
<artifactId>base-kv</artifactId>
<version>2.1.2</version>
<version>2.1.3-SNAPSHOT</version>
</parent>

<artifactId>base-kv-raft-type</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion base-kv/base-kv-raft/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>com.baidu.bifromq</groupId>
<artifactId>base-kv</artifactId>
<version>2.1.2</version>
<version>2.1.3-SNAPSHOT</version>
</parent>

<artifactId>base-kv-raft</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion base-kv/base-kv-store-balance-controller/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<parent>
<artifactId>base-kv</artifactId>
<groupId>com.baidu.bifromq</groupId>
<version>2.1.2</version>
<version>2.1.3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion base-kv/base-kv-store-balance-spi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<parent>
<artifactId>base-kv</artifactId>
<groupId>com.baidu.bifromq</groupId>
<version>2.1.2</version>
<version>2.1.3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion base-kv/base-kv-store-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>com.baidu.bifromq</groupId>
<artifactId>base-kv</artifactId>
<version>2.1.2</version>
<version>2.1.3-SNAPSHOT</version>
</parent>

<artifactId>base-kv-store-client</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion base-kv/base-kv-store-rpc-definition/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>com.baidu.bifromq</groupId>
<artifactId>base-kv</artifactId>
<version>2.1.2</version>
<version>2.1.3-SNAPSHOT</version>
</parent>

<artifactId>base-kv-store-rpc-definition</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion base-kv/base-kv-store-server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>com.baidu.bifromq</groupId>
<artifactId>base-kv</artifactId>
<version>2.1.2</version>
<version>2.1.3-SNAPSHOT</version>
</parent>

<artifactId>base-kv-store-server</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion base-kv/base-kv-type-proto/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>com.baidu.bifromq</groupId>
<artifactId>base-kv</artifactId>
<version>2.1.2</version>
<version>2.1.3-SNAPSHOT</version>
</parent>

<artifactId>base-kv-type-proto</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion base-kv/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<artifactId>bifromq-parent</artifactId>
<groupId>com.baidu.bifromq</groupId>
<version>2.1.2</version>
<version>2.1.3-SNAPSHOT</version>
</parent>
<packaging>pom</packaging>

Expand Down
2 changes: 1 addition & 1 deletion base-logger/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>com.baidu.bifromq</groupId>
<artifactId>bifromq-parent</artifactId>
<version>2.1.2</version>
<version>2.1.3-SNAPSHOT</version>
</parent>

<artifactId>base-logger</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion base-rpc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<artifactId>bifromq-parent</artifactId>
<groupId>com.baidu.bifromq</groupId>
<version>2.1.2</version>
<version>2.1.3-SNAPSHOT</version>
</parent>

<artifactId>base-rpc</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion base-scheduler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<parent>
<artifactId>bifromq-parent</artifactId>
<groupId>com.baidu.bifromq</groupId>
<version>2.1.2</version>
<version>2.1.3-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion bifromq-apiserver/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>com.baidu.bifromq</groupId>
<artifactId>bifromq-parent</artifactId>
<version>2.1.2</version>
<version>2.1.3-SNAPSHOT</version>
</parent>

<artifactId>bifromq-apiserver</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ enum State {
public APIServer(String host,
int port,
int tlsPort,
int maxContentLength,
EventLoopGroup bossGroup,
EventLoopGroup workerGroup,
SslContext sslContext,
Expand All @@ -73,10 +74,10 @@ public APIServer(String host,
IHTTPRouteMap routeMap = new HTTPRouteMap(new HTTPRequestHandlersFactory(sessionDictClient,
distClient, mqttBrokerClient, inboxClient, retainClient, settingProvider));
this.serverChannel =
buildServerChannel(port, new NonTLSServerInitializer(routeMap, settingProvider));
buildServerChannel(port, new NonTLSServerInitializer(routeMap, settingProvider, maxContentLength));
if (sslContext != null) {
this.tlsServerChannel =
buildServerChannel(tlsPort, new TLSServerInitializer(sslContext, routeMap, settingProvider));
buildServerChannel(tlsPort, new TLSServerInitializer(sslContext, routeMap, settingProvider, maxContentLength));
} else {
this.tlsServerChannel = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
abstract class AbstractServerInitializer extends ChannelInitializer<SocketChannel> {
protected final ISettingProvider settingProvider;
protected final IHTTPRouteMap routeMap;
protected final int maxContentLength;

public AbstractServerInitializer(IHTTPRouteMap routeMap, ISettingProvider settingProvider) {
public AbstractServerInitializer(IHTTPRouteMap routeMap, ISettingProvider settingProvider, int maxContentLength) {
this.settingProvider = settingProvider;
this.routeMap = routeMap;
this.maxContentLength = maxContentLength;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@
import com.baidu.bifromq.plugin.settingprovider.ISettingProvider;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;

public class NonTLSServerInitializer extends AbstractServerInitializer {
public NonTLSServerInitializer(IHTTPRouteMap routeMap, ISettingProvider settingProvider) {
super(routeMap, settingProvider);
public NonTLSServerInitializer(IHTTPRouteMap routeMap, ISettingProvider settingProvider, int maxContentLength) {
super(routeMap, settingProvider, maxContentLength);
}

@Override
protected void initChannel(SocketChannel ch) {
final ChannelPipeline p = ch.pipeline();
final HttpServerCodec sourceCodec = new HttpServerCodec();
p.addLast(sourceCodec);
p.addLast(new HttpObjectAggregator(maxContentLength));
p.addLast(new HTTPRequestRouter(routeMap, settingProvider));
p.addLast(ExceptionHandler.INSTANCE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,24 @@
import com.baidu.bifromq.apiserver.http.IHTTPRouteMap;
import com.baidu.bifromq.plugin.settingprovider.ISettingProvider;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.ssl.SslContext;

public class TLSServerInitializer extends AbstractServerInitializer {
private final SslContext sslContext;

public TLSServerInitializer(SslContext sslContext, IHTTPRouteMap routeMap, ISettingProvider settingProvider) {
super(routeMap, settingProvider);
public TLSServerInitializer(SslContext sslContext, IHTTPRouteMap routeMap, ISettingProvider settingProvider,
int maxContentLength) {
super(routeMap, settingProvider, maxContentLength);
this.sslContext = sslContext;
}

@Override
protected void initChannel(SocketChannel ch) {
ch.pipeline().addLast(sslContext.newHandler(ch.alloc()));
ch.pipeline().addLast(new HttpServerCodec());
ch.pipeline().addLast(new HttpObjectAggregator(maxContentLength));
ch.pipeline().addLast(new HTTPRequestRouter(routeMap, settingProvider));
ch.pipeline().addLast(ExceptionHandler.INSTANCE);
}
Expand Down
Loading

0 comments on commit a82c5a2

Please sign in to comment.