Repository navigation
Support 1-sample consumer queues (fixes #156, #158) - #334
Merged
Merged
Conversation
consumer_queue is a Vyukov-style bounded queue, which needs at least 2 slots: with 1, "occupied" and "free for the next round" share a sequence number. A 1-sample queue is reachable from the public API (an inlet's buffer rounds up to at least 1 sample, and a streamfeed request can send Max-Buffer-Length: 1). Debug builds aborted on assert(size_ > 1) (#158); release builds corrupted the queue (3 samples reported in 1 slot). A 1-sample queue now uses 2 slots and push_sample() drops the queued sample first, so it keeps exactly the newest one. data_receiver checked max_buflen < 0 only after building the queue with it, where a negative value becomes a huge size_t allocation (#156); the check now happens first. Fixes #156, fixes #158
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
consumer_queueis a Vyukov-style bounded MPMC queue, which needs at least 2 slots (with 1, an occupied slot and a slot that is free for the next round have the same sequence number). A 1-sample queue is reachable through the public API: an inlet's buffer is rounded up to at least 1 sample (e.g.transp_bufsize_sampleswithmax_buflen=1, or a slow stream), and any client can sendMax-Buffer-Length: 1in a streamfeed request.assert(size_ > 1)(Max-Buffer-Length: 1crashes the outlet process #158). Reproduced with the new test.read_available()reported 3 samples in 1 slot.Fix: a 1-sample queue uses 2 slots, and
push_sample()drops the queued sample before pushing, so it holds exactly the newest sample. That's the meaningful behavior for "buffer 1 sample" (e.g. always getting the latest value), and other sizes are unchanged except for one extra branch per push.#156:
data_receivercheckedmax_buflen < 0only after creating the queue with it, where a negative value becomes a huge allocation. The check now runs first.Tests: new
consumer_queue of one sampletest (fails in release, aborts in debug without the fix). Release:[queue], all internal (except the macOS-flaky "streambuf cancel connect()") and all 49 exported tests pass; Debug:[queue]passes.