Skip to content

fix(batcher): wait for in-flight flushes before flush() returns - #8420

Open
M-Colley wants to merge 1 commit into
getsentry:masterfrom
M-Colley:fix/issue-8300-batcher-flush-inflight
Open

M-Colley wants to merge 1 commit into
getsentry:masterfrom
M-Colley:fix/issue-8300-batcher-flush-inflight

Conversation

@M-Colley

Copy link
Copy Markdown

Description

Batcher._flush() and SpanBatcher._flush() previously released _lock before invoking _capture_func(), allowing concurrent flush() or close() calls to observe an empty buffer and return while the flusher thread was still delivering an in-flight batch to the transport. This change tracks active _capture_func() calls with _in_flight_flushes and a threading.Condition bound to _lock so external flush() calls wait within the remaining timeout budget until in-flight batches reach the transport. Re-entrant flush() calls invoked from inside _capture_func() skip waiting via _active.flag to prevent self-deadlock. In addition, Client._flush_components() and the test handshake wrapper in tests/conftest.py propagate the remaining timeout budget to batchers and transport flushing. Regression tests in tests/tracing/test_span_batcher.py and tests/test_logs.py cover in-flight handoffs in Batcher, SpanBatcher, Client.flush(), and Client.close(), re-entrant flush() safety, and timeout bounds.

Issues

Fixes getsentry#8300

Signed-off-by: Mark Colley <39366189+M-Colley@users.noreply.github.com>
@M-Colley
M-Colley requested a review from a team as a code owner November 28, 2026 10:48
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

PR risk: medium

For commit 437410a.

Main concerns: reach, public contract, host performance.

This label is a hint for reviewers, not an approval.

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

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

flush() can return before a batch taken by the flusher thread reaches the transport

1 participant