Skip to content

Commit

Permalink
Enhanced fix for #5855
Browse files Browse the repository at this point in the history
better atomic usage
  • Loading branch information
gregw committed Jan 6, 2021
1 parent 851ba75 commit 8258302
Showing 1 changed file with 5 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public CompletableFuture<Void> preCreateConnections(int connectionCount)
Pool<Connection>.Entry entry = pool.reserve();
if (entry == null)
break;
pending.addAndGetHi(1);
pending.add(1, 0);

Promise.Completable<Connection> future = new FutureConnection(entry);
futures.add(future);
Expand Down Expand Up @@ -270,7 +270,7 @@ protected void tryCreate()
if (entry == null)
{
// pool is full, so decrement reservations and return
pending.addAndGetHi(-1);
pending.add(-1, 0);
return;
}

Expand Down Expand Up @@ -480,20 +480,15 @@ public void succeeded(Connection connection)
((Attachable)connection).setAttachment(reserved);
onCreated(connection);

while (true)
{
long encoded = pending.get();
if (pending.compareAndSet(encoded, getHi(encoded) - 1, Math.max(0, getLo(encoded) - getMaxMultiplex())))
break;
}
pending.updateAndGet(encoded -> AtomicBiInteger.encode(getHi(encoded) - 1, Math.max(0, getLo(encoded) - getMaxMultiplex())));
reserved.enable(connection, false);
idle(connection, false);
complete(null);
proceed();
}
else
{
pending.addAndGetHi(-1);
pending.add(-1, 0);
failed(new IllegalArgumentException("Invalid connection object: " + connection));
}
}
Expand All @@ -503,7 +498,7 @@ public void failed(Throwable x)
{
if (LOG.isDebugEnabled())
LOG.debug("Connection creation failed {}", reserved, x);
pending.addAndGetHi(-1);
pending.add(-1, 0);
reserved.remove();
completeExceptionally(x);
requester.failed(x);
Expand Down

0 comments on commit 8258302

Please sign in to comment.