Skip to content

Commit ea8efac

Browse files
committed
Turn AUTO_CLOSE to false
1 parent 511134a commit ea8efac

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

client/src/main/java/org/asynchttpclient/netty/channel/ChannelManager.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ public class ChannelManager {
8787
private final SslEngineFactory sslEngineFactory;
8888
private final EventLoopGroup eventLoopGroup;
8989
private final boolean allowReleaseEventLoopGroup;
90-
private final Class<? extends Channel> socketChannelClass;
9190
private final Bootstrap httpBootstrap;
9291
private final Bootstrap wsBootstrap;
9392
private final long handshakeTimeout;
@@ -159,6 +158,7 @@ public boolean remove(Object o) {
159158
// check if external EventLoopGroup is defined
160159
ThreadFactory threadFactory = config.getThreadFactory() != null ? config.getThreadFactory() : new DefaultThreadFactory(config.getThreadPoolName());
161160
allowReleaseEventLoopGroup = config.getEventLoopGroup() == null;
161+
Class<? extends Channel> socketChannelClass;
162162
if (allowReleaseEventLoopGroup) {
163163
if (config.isUseNativeTransport()) {
164164
eventLoopGroup = newEpollEventLoopGroup(threadFactory);
@@ -181,23 +181,28 @@ public boolean remove(Object o) {
181181
}
182182
}
183183

184-
httpBootstrap = new Bootstrap().channel(socketChannelClass).group(eventLoopGroup);
185-
wsBootstrap = new Bootstrap().channel(socketChannelClass).group(eventLoopGroup);
184+
httpBootstrap = newBootstrap(socketChannelClass, eventLoopGroup, config);
185+
wsBootstrap = newBootstrap(socketChannelClass, eventLoopGroup, config);
186186

187-
// default to PooledByteBufAllocator
188-
httpBootstrap.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
189-
wsBootstrap.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
187+
// for reactive streams
188+
httpBootstrap.option(ChannelOption.AUTO_READ, false);
189+
}
190+
191+
private Bootstrap newBootstrap(Class<? extends Channel> socketChannelClass, EventLoopGroup eventLoopGroup, AsyncHttpClientConfig config) {
192+
Bootstrap bootstrap = new Bootstrap().channel(socketChannelClass).group(eventLoopGroup)//
193+
// default to PooledByteBufAllocator
194+
.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT)//
195+
.option(ChannelOption.AUTO_CLOSE, false);
190196

191197
if (config.getConnectTimeout() > 0) {
192-
httpBootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.getConnectTimeout());
193-
wsBootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.getConnectTimeout());
198+
bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, config.getConnectTimeout());
194199
}
200+
195201
for (Entry<ChannelOption<Object>, Object> entry : config.getChannelOptions().entrySet()) {
196-
ChannelOption<Object> key = entry.getKey();
197-
Object value = entry.getValue();
198-
httpBootstrap.option(key, value);
199-
wsBootstrap.option(key, value);
202+
bootstrap.option(entry.getKey(), entry.getValue());
200203
}
204+
205+
return bootstrap;
201206
}
202207

203208
private EventLoopGroup newEpollEventLoopGroup(ThreadFactory threadFactory) {
@@ -238,8 +243,6 @@ protected void initChannel(Channel ch) throws Exception {
238243
.addLast(CHUNKED_WRITER_HANDLER, new ChunkedWriteHandler())//
239244
.addLast(AHC_HTTP_HANDLER, httpHandler);
240245

241-
ch.config().setOption(ChannelOption.AUTO_READ, false);
242-
243246
if (config.getHttpAdditionalChannelInitializer() != null)
244247
config.getHttpAdditionalChannelInitializer().initChannel(ch);
245248
}
@@ -376,7 +379,7 @@ private HttpClientCodec newHttpClientCodec() {
376379
config.getHttpClientCodecMaxInitialLineLength(),//
377380
config.getHttpClientCodecMaxHeaderSize(),//
378381
config.getHttpClientCodecMaxChunkSize(),//
379-
false,
382+
false,//
380383
config.isValidateResponseHeaders());
381384
}
382385

0 commit comments

Comments
 (0)