Skip to content

[SDK] Fix lost wakeup in BatchSpanProcessor OnEnd notify - #4741

Merged
marcalff merged 4 commits into
open-telemetry:mainfrom
ltowarek:batch-processor-lost-wakeup
Nov 1, 2026
Merged

marcalff merged 4 commits into
open-telemetry:mainfrom
ltowarek:batch-processor-lost-wakeup

Conversation

@ltowarek

Copy link
Copy Markdown
Contributor

Follow-up to #4727 (review comment).

Changes

When the queue is full, new spans are dropped before they wake the worker. So the span that fills the queue must wake it. OnEnd sent that notify without holding cv_m, so it could be lost. The worker then slept until schedule_delay_millis and all new spans were dropped.

OnEnd now notifies under cv_m when the queue is full, like ForceFlush and Shutdown do since #4382. Other notifies stay lock-free.

Also adds a stress test for this, with small helpers shared by the existing stress tests. The clamp test added in #4727 no longer needs its sleep, because the notify from its last span can no longer be lost. It now also stops the worker before reading the batch sizes, so a late export cannot race the read.

For significant contributions please make sure you have completed the following items:

  • CHANGELOG.md updated for non-trivial changes
  • Unit tests have been added
  • Changes in public API reviewed

The worker waits for a full batch, and once the queue is full later
spans are dropped before they notify. OnEnd notified without cv_m, so
the notify from the span that fills the queue could be lost, parking
the worker with a full queue until the schedule delay. With
max_export_batch_size clamped to max_queue_size that span is the only
one that completes a batch. Notify under cv_m when the queue is full,
as ForceFlush and Shutdown already do; the other notifies stay
lock-free.

Add an OnEnd stress test in the style of the existing ones, with
BusySpin and ShutdownWithWatchdog helpers now shared by all three
stress tests. The clamp test no longer sleeps before the last span,
and it stops the worker before reading batch_sizes so a late export
cannot race the read.
MSVC rejects the non-captured local constexpr kQueueSize inside the
lambda (C3493). A static local needs no capture.
@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.62%. Comparing base (90af189) to head (fbe892f).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4741      +/-   ##
==========================================
+ Coverage   86.61%   86.62%   +0.01%     
==========================================
  Files         530      530              
  Lines       21165    21169       +4     
==========================================
+ Hits        18331    18335       +4     
  Misses       2834     2834              
Files with missing lines Coverage Δ
sdk/src/trace/batch_span_processor.cc 92.52% <100.00%> (+0.17%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ltowarek
ltowarek marked this pull request as ready for review October 28, 2026 05:36
@ltowarek
ltowarek requested a review from a team as a code owner October 28, 2026 05:36

@mateenali66 mateenali66 left a comment

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.

checked that the new tests catch the bug. with this PR's two test files on 0c630dc, OnEndRacesWorkerPark hits the watchdog in 7 of 7 runs, at rounds 336 to 580, and the clamp test without its sleep fails 26 of 300. at 8732d49 both pass, 20 of 20 and 300 of 300, and both batch span processor binaries are tsan clean. the lock is taken only by the span that fills the queue, so the usual notify stays lock free.

non-blocking, for later: the logs processor keeps the lock-free notify at batch_log_record_processor.cc:109. its worker parks only on an empty buffer (:217), so the window there is the whole empty-to-full fill. it will need the same change once #4498 brings the full-batch wait from #4466 to logs.

@marcalff marcalff left a comment

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.

LGTM, thanks for the fix.

@marcalff marcalff changed the title Fix lost wakeup in BatchSpanProcessor OnEnd notify [SDK] Fix lost wakeup in BatchSpanProcessor OnEnd notify Nov 1, 2026
@marcalff
marcalff merged commit 88dea80 into open-telemetry:main Nov 1, 2026
132 of 140 checks passed
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.

3 participants