netty5/common/src
Chris Vest dde82f62f0
Fix bug in Recycler with racing calls to recycle ()
Motivation:
It is possible for two separate threads to race on recycling an object.
If this happens, the object might be added to a WeakOrderQueue when it shouldn't be.
The end result of this is that an object could be acquired multiple times, without a recycle in between.
Effectively, it ends up in circulation twice.

Modification:
We fix this by making the update to the lastRecycledId field of the handle, an atomic state transition.
Only the thread that "wins" the race and succeeds in their state transition will be allowed to recycle the object.
The others will bail out on their recycling.
We use weakCompareAndSet because we only need the atomicity guarantee, and the program order within each thread is sufficient.
Also, spurious failures just means we won't recycle that particular object, which is fine.

Result:
Objects no longer risk circulating twice due to a recycle race.

This fixes 
2021-02-26 10:02:49 +01:00
..
main Fix bug in Recycler with racing calls to recycle () 2021-02-26 10:02:49 +01:00
test Fix bug in Recycler with racing calls to recycle () 2021-02-26 10:02:49 +01:00