Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ByteBufferPool race condition #5778

Merged
merged 1 commit into from Dec 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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