Skip to content

Commit 8ee46ad

Browse files
committed
Release semaphores when only maxConnectionsPerHost is enabled, closed AsyncHttpClient#920
1 parent d046bb5 commit 8ee46ad

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

providers/netty3/src/main/java/org/asynchttpclient/netty/channel/ChannelManager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,14 @@ public ChannelManager(final AsyncHttpClientConfig config, NettyAsyncHttpProvider
129129
maxTotalConnectionsEnabled = config.getMaxConnections() > 0;
130130
maxConnectionsPerHostEnabled = config.getMaxConnectionsPerHost() > 0;
131131

132-
if (maxTotalConnectionsEnabled) {
132+
if (maxTotalConnectionsEnabled || maxConnectionsPerHostEnabled) {
133133
openChannels = new CleanupChannelGroup("asyncHttpClient") {
134134
@Override
135135
public boolean remove(Object o) {
136136
boolean removed = super.remove(o);
137137
if (removed) {
138-
freeChannels.release();
138+
if (maxTotalConnectionsEnabled)
139+
freeChannels.release();
139140
if (maxConnectionsPerHostEnabled) {
140141
Object partitionKey = channelId2PartitionKey.remove(Channel.class.cast(o).getId());
141142
if (partitionKey != null) {

providers/netty4/src/main/java/org/asynchttpclient/netty/channel/ChannelManager.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,14 @@ public ChannelManager(final AsyncHttpClientConfig config, NettyAsyncHttpProvider
125125
maxTotalConnectionsEnabled = config.getMaxConnections() > 0;
126126
maxConnectionsPerHostEnabled = config.getMaxConnectionsPerHost() > 0;
127127

128-
if (maxTotalConnectionsEnabled) {
128+
if (maxTotalConnectionsEnabled || maxConnectionsPerHostEnabled) {
129129
openChannels = new CleanupChannelGroup("asyncHttpClient") {
130130
@Override
131131
public boolean remove(Object o) {
132132
boolean removed = super.remove(o);
133133
if (removed) {
134-
freeChannels.release();
134+
if (maxTotalConnectionsEnabled)
135+
freeChannels.release();
135136
if (maxConnectionsPerHostEnabled) {
136137
Object partitionKey = channelId2PartitionKey.remove(Channel.class.cast(o));
137138
if (partitionKey != null) {

0 commit comments

Comments
 (0)