Skip to content

Support 1-sample consumer queues (fixes #156, #158) - #334

Merged
cboulay merged 1 commit into
devfrom
fix/consumer-queue-size
Oct 14, 2026
Merged

cboulay merged 1 commit into
devfrom
fix/consumer-queue-size

Conversation

@cboulay

@cboulay cboulay commented Oct 14, 2026

Copy link
Copy Markdown
Collaborator

consumer_queue is 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_samples with max_buflen=1, or a slow stream), and any client can send Max-Buffer-Length: 1 in a streamfeed request.

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_receiver checked max_buflen < 0 only 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 sample test (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.

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
@cboulay
cboulay merged commit 4adc8da into dev Oct 14, 2026
57 checks passed
@cboulay
cboulay deleted the fix/consumer-queue-size branch October 14, 2026 19:55
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.

1 participant