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
[#4198] Fix race-condition when allocate from multiple-thread. #4388
Conversation
@Scottmitch @nmittler PTAL |
} | ||
// Obtain the head of the PoolSubPage pool that is owned by the PoolArena and synchronize on it. | ||
// This is need as we may add it back and so alter the linked-list structure. | ||
PoolSubpage<T> head = arena.findSubpagePoolHead(normCapacity); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not just synchronize on the arena, itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because we want to minimize the overhead as much as possible. With this it is possible to allocate out of different PoolSubPage pools concurrently ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are different for different requested sizes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK as long as you're confident that this will fix the race, LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes I am :) You can also run the test-case that is included. It will fail before and now pass :)
4e634e9
to
777c2bf
Compare
@Scottmitch I think I addressed your concerns... Also I improved the test so we are sure we not leak any buffers. |
777c2bf
to
b59cb94
Compare
@merlimat once you verified I will pull in a cut a release ASAP |
@normanmaurer everything looks great, thanks! |
@merlimat verified the fix... @Scottmitch @nmittler ready for cherry-pick ? |
Yeah, go for it! |
long sleepTime = 500; | ||
long startTime = System.currentTimeMillis(); | ||
long endTime = startTime + runningTime; | ||
for (; startTime < endTime; startTime += sleepTime) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we are still vulnerable to overflow here. Also why switch to currentTimeMillis
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we vulnerable to overflow ? If we not have enough left after adding stuff to to System.currentTimeMillis() I think we have bigger problems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Scottmitch actually I think we not even need this.... Let me update
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we do have bigger problems, but lets not make those problems worse 😄
We could use something like this:
long start = nanoTime();
long expireTime = // 30 seconds...or w/e you need
while (!isExpired(start, expireTime)) {
...
}
private static boolean isExpired(long start, long expireTime) {
return nanoTime() - start > expireTime;
}
b59cb94
to
014c97f
Compare
Motivation: Fix a race condition that was introduced by f18990a that could lead to a NPE when allocate from the PooledByteBufAllocator concurrently by many threads. Modifications: Correctly synchronize on the PoolSubPage head. Result: No more race.
014c97f
to
e01484e
Compare
@normanmaurer - lgtm |
Motivation:
Fix a race condition that was introduced by f18990a that could lead to a NPE when allocate from the PooledByteBufAllocator concurrently by many threads.
Modifications:
Correctly synchronize on the PoolSubPage head.
Result:
No more race.