@@ -133,9 +133,7 @@ public ChannelManager(final AsyncHttpClientConfig config, Timer nettyTimer) {
133
133
maxTotalConnectionsEnabled = config .getMaxConnections () > 0 ;
134
134
maxConnectionsPerHostEnabled = config .getMaxConnectionsPerHost () > 0 ;
135
135
136
- freeChannels = maxTotalConnectionsEnabled ?
137
- new NonBlockingSemaphore (config .getMaxConnections ()) :
138
- NonBlockingSemaphoreInfinite .INSTANCE ;
136
+ freeChannels = maxTotalConnectionsEnabled ? new NonBlockingSemaphore (config .getMaxConnections ()) : NonBlockingSemaphoreInfinite .INSTANCE ;
139
137
140
138
if (maxTotalConnectionsEnabled || maxConnectionsPerHostEnabled ) {
141
139
openChannels = new DefaultChannelGroup ("asyncHttpClient" , GlobalEventExecutor .INSTANCE ) {
@@ -309,16 +307,15 @@ public final void tryToOfferChannelToPool(Channel channel, AsyncHandler<?> async
309
307
if (asyncHandler instanceof AsyncHandlerExtensions )
310
308
AsyncHandlerExtensions .class .cast (asyncHandler ).onConnectionOffer (channel );
311
309
if (channelPool .offer (channel , partitionKey )) {
312
- if (maxConnectionsPerHostEnabled )
310
+ if (maxConnectionsPerHostEnabled ) {
313
311
channel .attr (partitionKeyAttr ).setIfAbsent (partitionKey );
314
- } else {
315
- // rejected by pool
316
- closeChannel (channel );
312
+ }
313
+ return ;
317
314
}
318
- } else {
319
- // not offered
320
- closeChannel (channel );
321
315
}
316
+ // rejected by pool or not offered
317
+ releaseChannelLock (partitionKey );
318
+ closeChannel (channel );
322
319
}
323
320
324
321
public Channel poll (Uri uri , String virtualHost , ProxyServer proxy , ChannelPoolPartitioning connectionPoolPartitioning ) {
@@ -335,9 +332,8 @@ private boolean tryAcquireGlobal() {
335
332
}
336
333
337
334
private NonBlockingSemaphoreLike getFreeConnectionsForHost (Object partitionKey ) {
338
- return maxConnectionsPerHostEnabled ?
339
- freeChannelsPerHost .computeIfAbsent (partitionKey , pk -> new NonBlockingSemaphore (config .getMaxConnectionsPerHost ())) :
340
- NonBlockingSemaphoreInfinite .INSTANCE ;
335
+ return maxConnectionsPerHostEnabled ? freeChannelsPerHost .computeIfAbsent (partitionKey , pk -> new NonBlockingSemaphore (config .getMaxConnectionsPerHost ()))
336
+ : NonBlockingSemaphoreInfinite .INSTANCE ;
341
337
}
342
338
343
339
private boolean tryAcquirePerHost (Object partitionKey ) {
0 commit comments