@@ -93,7 +93,7 @@ public class ChannelManager {
93
93
private final IOException poolAlreadyClosed ;
94
94
95
95
private final ChannelPool channelPool ;
96
- private final boolean maxConnectionsEnabled ;
96
+ private final boolean maxTotalConnectionsEnabled ;
97
97
private final Semaphore freeChannels ;
98
98
private final ChannelGroup openChannels ;
99
99
private final boolean maxConnectionsPerHostEnabled ;
@@ -119,10 +119,10 @@ public ChannelManager(AsyncHttpClientConfig config, NettyAsyncHttpProviderConfig
119
119
tooManyConnections = buildStaticException (String .format ("Too many connections %s" , config .getMaxConnections ()));
120
120
tooManyConnectionsPerHost = buildStaticException (String .format ("Too many connections per host %s" , config .getMaxConnectionsPerHost ()));
121
121
poolAlreadyClosed = buildStaticException ("Pool is already closed" );
122
- maxConnectionsEnabled = config .getMaxConnections () > 0 ;
122
+ maxTotalConnectionsEnabled = config .getMaxConnections () > 0 ;
123
123
maxConnectionsPerHostEnabled = config .getMaxConnectionsPerHost () > 0 ;
124
124
125
- if (maxConnectionsEnabled ) {
125
+ if (maxTotalConnectionsEnabled ) {
126
126
openChannels = new CleanupChannelGroup ("asyncHttpClient" ) {
127
127
@ Override
128
128
public boolean remove (Object o ) {
@@ -280,7 +280,7 @@ public boolean removeAll(Channel connection) {
280
280
}
281
281
282
282
private boolean tryAcquireGlobal () {
283
- return !maxConnectionsEnabled || freeChannels .tryAcquire ();
283
+ return !maxTotalConnectionsEnabled || freeChannels .tryAcquire ();
284
284
}
285
285
286
286
private Semaphore getFreeConnectionsForHost (String poolKey ) {
@@ -304,8 +304,12 @@ public void preemptChannel(String poolKey) throws IOException {
304
304
throw poolAlreadyClosed ;
305
305
if (!tryAcquireGlobal ())
306
306
throw tooManyConnections ;
307
- if (!tryAcquirePerHost (poolKey ))
307
+ if (!tryAcquirePerHost (poolKey )) {
308
+ if (maxTotalConnectionsEnabled )
309
+ freeChannels .release ();
310
+
308
311
throw tooManyConnectionsPerHost ;
312
+ }
309
313
}
310
314
311
315
public void close () {
@@ -334,7 +338,7 @@ public void closeChannel(Channel channel) {
334
338
}
335
339
336
340
public void abortChannelPreemption (String poolKey ) {
337
- if (maxConnectionsEnabled )
341
+ if (maxTotalConnectionsEnabled )
338
342
freeChannels .release ();
339
343
if (maxConnectionsPerHostEnabled )
340
344
getFreeConnectionsForHost (poolKey ).release ();
0 commit comments