Repository navigation
fix: keep send queue byte budget while flushing - #128
Open
adityajai119 wants to merge 1 commit into
Open
adityajai119 wants to merge 1 commit into
adityajai119 wants to merge 1 commit into
Conversation
flush_sync/flush_async cleared the byte counter before handing messages to send(), so enqueues during a flush could fill the whole budget again. When a send failed, the requeued unsent messages plus those new entries pushed the queue past max_bytes. Keep in-flight bytes counted and release them only after a successful send so the limit holds across retries.
This branch has not been deployed
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.
What
\SendQueue.flush_sync()\ and \lush_async()\ reset _bytes\ to zero before handing the queued messages to \send(). Messages that are in flight are no longer counted against \max_bytes, so another producer can fill the entire budget again while the flush is running. If a send then fails, the requeued unsent messages plus the newly enqueued ones push the queue over \max_bytes.
Concretely, with \max_bytes=10, two queued 5-byte messages, and a failed first send, an enqueue that happens during the flush leaves 15 bytes in the queue after requeue.
Fix
Keep the in-flight byte count in _bytes\ when a flush starts, and subtract a message's byte length only after \send()\ succeeds. Enqueues during the flush are now rejected when they would exceed the real budget, so the requeue path can never exceed \max_bytes.
Testing
Added sync and async regression tests in \ ests/test_send_queue.py\ asserting the requeued queue stays within the byte limit. Before the fix both fail with 15 > 10; after the fix:
uff check\ and
uff format --check\ on both changed files -> clean