-
Notifications
You must be signed in to change notification settings - Fork 125
Description
The PooledBlockAllocatorProvider stores its pooled values in a ConcurrentLinkedQueue:
Later, when one of those instances is returned to the pool, this code runs:
Unfortunately, ConcurrentLinkedQueue's documentation for the size() method says:
Beware that, unlike in most collections, this method is NOT a constant-time operation. Because of the asynchronous nature of these queues, determining the current number of elements requires an O(n) traversal. Additionally, if elements are added or removed during execution of this method, the returned result may be inaccurate. Thus, this method is typically not very useful in concurrent applications.
Under high contention, this could lead to some number of instances being discarded rather than added to the pool or vice versa.
We're not relying on the non-blocking nature of the ConcurrentLinkedQueue, so we can probably just swap this out for an ArrayBlockingQueue.