Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit06c58c6

Browse files
committed
Release channel lock when channel is not offered to pool, seeAsyncHttpClient#1377
1 parent2d76bbd commit06c58c6

File tree

2 files changed

+12
-15
lines changed

2 files changed

+12
-15
lines changed

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,7 @@ public ChannelManager(final AsyncHttpClientConfig config, Timer nettyTimer) {
133133
maxTotalConnectionsEnabled =config.getMaxConnections() >0;
134134
maxConnectionsPerHostEnabled =config.getMaxConnectionsPerHost() >0;
135135

136-
freeChannels =maxTotalConnectionsEnabled ?
137-
newNonBlockingSemaphore(config.getMaxConnections()) :
138-
NonBlockingSemaphoreInfinite.INSTANCE;
136+
freeChannels =maxTotalConnectionsEnabled ?newNonBlockingSemaphore(config.getMaxConnections()) :NonBlockingSemaphoreInfinite.INSTANCE;
139137

140138
if (maxTotalConnectionsEnabled ||maxConnectionsPerHostEnabled) {
141139
openChannels =newDefaultChannelGroup("asyncHttpClient",GlobalEventExecutor.INSTANCE) {
@@ -309,16 +307,15 @@ public final void tryToOfferChannelToPool(Channel channel, AsyncHandler<?> async
309307
if (asyncHandlerinstanceofAsyncHandlerExtensions)
310308
AsyncHandlerExtensions.class.cast(asyncHandler).onConnectionOffer(channel);
311309
if (channelPool.offer(channel,partitionKey)) {
312-
if (maxConnectionsPerHostEnabled)
310+
if (maxConnectionsPerHostEnabled) {
313311
channel.attr(partitionKeyAttr).setIfAbsent(partitionKey);
314-
}else {
315-
// rejected by pool
316-
closeChannel(channel);
312+
}
313+
return;
317314
}
318-
}else {
319-
// not offered
320-
closeChannel(channel);
321315
}
316+
// rejected by pool or not offered
317+
releaseChannelLock(partitionKey);
318+
closeChannel(channel);
322319
}
323320

324321
publicChannelpoll(Uriuri,StringvirtualHost,ProxyServerproxy,ChannelPoolPartitioningconnectionPoolPartitioning) {
@@ -335,9 +332,8 @@ private boolean tryAcquireGlobal() {
335332
}
336333

337334
privateNonBlockingSemaphoreLikegetFreeConnectionsForHost(ObjectpartitionKey) {
338-
returnmaxConnectionsPerHostEnabled ?
339-
freeChannelsPerHost.computeIfAbsent(partitionKey,pk ->newNonBlockingSemaphore(config.getMaxConnectionsPerHost())) :
340-
NonBlockingSemaphoreInfinite.INSTANCE;
335+
returnmaxConnectionsPerHostEnabled ?freeChannelsPerHost.computeIfAbsent(partitionKey,pk ->newNonBlockingSemaphore(config.getMaxConnectionsPerHost()))
336+
:NonBlockingSemaphoreInfinite.INSTANCE;
341337
}
342338

343339
privatebooleantryAcquirePerHost(ObjectpartitionKey) {

‎client/src/main/java/org/asynchttpclient/netty/handler/HttpHandler.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ private void finishUpdate(final NettyResponseFuture<?> future, Channel channel,
4949
future.cancelTimeouts();
5050

5151
booleankeepAlive =future.isKeepAlive();
52-
if (expectOtherChunks &&keepAlive)
52+
if (expectOtherChunks &&keepAlive) {
5353
channelManager.drainChannelAndOffer(channel,future);
54-
else
54+
}else {
5555
channelManager.tryToOfferChannelToPool(channel,future.getAsyncHandler(),keepAlive,future.getPartitionKey());
56+
}
5657

5758
try {
5859
future.done();

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp