Skip to content

Fix record loss when flushing bounded asynchronous queues - #260

Closed
dchristle wants to merge 1 commit into
boostorg:developfrom
dchristle:fix/bounded-queue-flush
Closed

dchristle wants to merge 1 commit into
boostorg:developfrom
dchristle:fix/bounded-queue-flush

Conversation

@dchristle

@dchristle dchristle commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Flushing an asynchronous sink can silently discard records from producers waiting for queue space. This affects both bounded_fifo_queue and bounded_ordering_queue when used with block_on_overflow.

flush() uses the same queue wake-up operation as stop(). For bounded queues, that operation also cancels producers blocked by the overflow policy. Their consume() calls then return without enqueueing their records.

Separate waking the consumer from cancelling blocked producers. Flushing the built-in bounded queues now wakes only the consumer, allowing blocked producers to enqueue their records as space becomes available. stop() retains its existing cancellation behavior.

The bounded policies expose a separate interrupt_dequeue_for_flush() hook. Other custom queue strategies continue through their existing no-argument interruption call unless they provide the new hook. Using a distinct name preserves existing overloads such as interrupt_dequeue(bool wake = true) without assigning a new meaning to their arguments.

Separate FIFO and ordering regression executables each pause the backend on a first record, fill a one-slot queue with a second record, and block a third producer for queue space. They then start a flush and release the backend. Before the fix, all three producer calls return but only two records reach the backend. With the fix, all three records are delivered.

A third executable checks that a legacy custom queue with a defaulted boolean interruption argument keeps its original wake behavior. All three tests have ten-second process watchdogs and pass on macOS with C++11.

Flushing a bounded queue interrupts its overflow strategy, causing
blocked producers to return without enqueuing their records.

Separate dequeue wakeup from producer cancellation for built-in bounded
queues. Use a distinct optional flush hook with a no-argument fallback
so existing custom interruption overloads retain their semantics.
Preserve cancellation for stop, and cover delivery and compatibility
with separate regression executables guarded by process deadlines.
@dchristle
dchristle force-pushed the fix/bounded-queue-flush branch from 838c40b to 673f5fe Compare November 8, 2026 21:20
@Lastique

Lastique commented Nov 9, 2026

Copy link
Copy Markdown
Member

I think, I'd prefer a different approach:

  • Rename interrupt_dequeue -> interrupt(bool dequeue, bool enqueue) in all queueing strategies. The method would interrupt only the requested operations. In the unbounded strategies, the enqueue parameter would be unused.
  • Call interrupt(true, true) on stop() and interrupt(true, false) on flush(). No need for the SFINAE checks.

Re. tests, it would be better if this could be tested without mocking the queueing strategies. I think, you can just write a test sink backend that will block on a condition variable or something on receiving a log record, until you signal it after invoking flush. You can use the same backend with both vanilla bounded_fifo_queue and bounded_ordering_queue strategies.

In general, I prefer when tests use the exact components that are provided by the library through their public interfaces rather their mocked variants because it is easier to understand what is being tested and avoid testing or depending on implementation details. This also pertains to your other PRs.

Comment on lines +23 to +24
namespace logging = boost::log;
namespace sinks = boost::log::sinks;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Namespace aliases should be avoided in headers, these tend to create issues like this. Just use full namespace qualification in headers.

@Lastique Lastique closed this in bac5f4f Nov 13, 2026
@Lastique

Copy link
Copy Markdown
Member

Thank you for the PR, I've merged my version of the fix.

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.

2 participants