Skip to content

Commit

Permalink
Enhanced fix for #5855
Browse files Browse the repository at this point in the history
increment demand even if pool is at max size.
  • Loading branch information
gregw committed Jan 6, 2021
1 parent 5083864 commit b854b34
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions jetty-util/src/main/java/org/eclipse/jetty/util/Pool.java
Expand Up @@ -268,25 +268,23 @@ public Entry reserve()
if (closed)
return null;

int space = maxEntries - entries.size();
if (space <= 0)
return null;

// Loop to update atomic pending as other mutators do not use lock.
while (true)
{
long encoded = pending.get();
int reserved = AtomicBiInteger.getLo(encoded);
int demand = AtomicBiInteger.getHi(encoded);

if (reserved * getMaxMultiplex() <= demand)
// If we have space and there is demand for a new entry
if (entries.size() < maxEntries && reserved * getMaxMultiplex() <= demand)
{
// we need a new connection
// create a new entry and increment demand
if (pending.compareAndSet(encoded, demand + 1, reserved + 1))
break;
}
else
{
// We increment demand on existing reservations
// We either can't create or don't need a new entry, so only increment demand
if (pending.compareAndSet(encoded, demand + 1, reserved))
return null;
}
Expand Down

0 comments on commit b854b34

Please sign in to comment.