Skip to content

fix: keep send queue byte budget while flushing - #128

Open
adityajai119 wants to merge 1 commit into
cartesia-ai:mainfrom
adityajai119:fix/send-queue-byte-budget
Open

adityajai119 wants to merge 1 commit into
cartesia-ai:mainfrom
adityajai119:fix/send-queue-byte-budget

Conversation

@adityajai119

Copy link
Copy Markdown

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:

  • \pytest tests/test_send_queue.py tests/lib/resources/stt -q\ -> 98 passed

  • uff check\ and
    uff format --check\ on both changed files -> clean

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

No deployments
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