Skip to content

Commit

Permalink
Merge pull request #5778 from eclipse/jetty-9.4.x-5775-ByteBufferPool…
Browse files Browse the repository at this point in the history
…-timestamp-fix

fix ByteBufferPool race condition
  • Loading branch information
lorban authored Dec 9, 2020
2 parents be5d968 + 4151965 commit ea621ce
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.List;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Consumer;

import org.eclipse.jetty.util.BufferUtil;
Expand Down Expand Up @@ -158,7 +159,7 @@ class Bucket
private final int _capacity;
private final int _maxSize;
private final AtomicInteger _size;
private long _lastUpdate = System.nanoTime();
private final AtomicLong _lastUpdate = new AtomicLong(System.nanoTime());

public Bucket(ByteBufferPool pool, int capacity, int maxSize)
{
Expand Down Expand Up @@ -196,7 +197,7 @@ public ByteBuffer acquire(boolean direct)

public void release(ByteBuffer buffer)
{
_lastUpdate = System.nanoTime();
_lastUpdate.lazySet(System.nanoTime());
BufferUtil.clear(buffer);
if (_size == null)
queueOffer(buffer);
Expand Down Expand Up @@ -251,7 +252,7 @@ int size()

long getLastUpdate()
{
return _lastUpdate;
return _lastUpdate.get();
}

@Override
Expand Down

0 comments on commit ea621ce

Please sign in to comment.