Skip to content

Commit

Permalink
fix race condition that may make the bucket cleaning pick the wrong o…
Browse files Browse the repository at this point in the history
…ne in case the timestamp is read while being modified
  • Loading branch information
lorban committed Dec 9, 2020
1 parent be5d968 commit 4151965
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 4151965

Please sign in to comment.