Skip to content

fix: prevent premature false return from RingBuffer Offer under contention - #240

Open
AdamMagued wants to merge 1 commit into
Workiva:masterfrom
AdamMagued:fix-ringbuffer-offer-contention
Open

AdamMagued wants to merge 1 commit into
Workiva:masterfrom
AdamMagued:fix-ringbuffer-offer-contention

Conversation

@AdamMagued

Copy link
Copy Markdown

In the MPMC RingBuffer put method, when offer is true, a failed CAS contention or slot lag previously caused put to fall through and immediately return false, nil as if the queue were full even when ample capacity remained.

Check whether the ring buffer is genuinely full before attempting slot reservation and retry upon CAS contention when capacity is available. Add concurrent regression test TestRingQueueOffer_parallel reproducing multiple goroutines invoking Offer concurrently.

Fixes #213

…ntion

In the MPMC RingBuffer put method, when offer is true, a failed CAS contention or slot lag previously caused put to fall through and immediately return false, nil as if the queue were full even when ample capacity remained.

Check whether the ring buffer is genuinely full before attempting slot reservation and retry upon CAS contention when capacity is available. Add concurrent regression test TestRingQueueOffer_parallel.

Fixes Workiva#213
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RingBuffer's Offer returns false (queue full) even when there is space in queue

1 participant