Repository navigation
Return a completed result from BatchSpanProcessor#forceFlush after shutdown - #9082
Open
TimurRakhmatullin86 wants to merge 1 commit into
Open
TimurRakhmatullin86 wants to merge 1 commit into
TimurRakhmatullin86 wants to merge 1 commit into
Conversation
Pull request dashboard statusWaiting on reviewers · refreshed 2026-11-30 16:57 UTC Review the latest changes. Status above doesn't look right?
|
…utdown After shutdown() the worker thread has flipped isShutdown and exited. A later call to forceFlush() would CAS a fresh flushRequested and offer a signal, but nothing is left to drain it or call succeed() on the returned future, so callers that block on it (for example join()) wait until their own user-supplied timeout. Guard forceFlush() with the worker's isShutdown atomic so it returns CompletableResultCode.ofSuccess() when the processor is already shut down. Mirrors the no-op success behavior already used by the shutdown re-entry guard. The internal Worker.forceFlush() path that shutdown() uses itself stays untouched, because shutdown() still needs the final flush even after it set isShutdown. Test: shutdown() first, then processor.forceFlush() returns an already-done successful result. Without the fix the result stays pending and the test blocks on join().
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9082 +/- ##
=========================================
Coverage 90.52% 90.53%
- Complexity 11243 11244 +1
=========================================
Files 1039 1039
Lines 30678 30681 +3
Branches 4015 4015
=========================================
+ Hits 27772 27776 +4
Misses 1928 1928
+ Partials 978 977 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
Summary
BatchSpanProcessor.forceFlush()invoked aftershutdown()returns aCompletableResultCodethat never completes.Call sequence
shutdown()runs, which callsworker.shutdown(). Worker flipsisShutdowntotrue, performs its final flush, and setscontinueWork = false. The worker thread'swhile (continueWork)loop exits.processor.forceFlush()afterwards. This delegates toworker.forceFlush(), which CASesflushRequestedfromnullto a freshCompletableResultCodeandsignal.offer(true).flushRequestedor callsucceed()on it. The future stays pending.join(),whenComplete(...).join(...)) wait until their own user-supplied timeout.This pattern bites users who flush on shutdown hooks or trigger
forceFlush()from a cleanup path that runs after a programmaticshutdown().Fix
Guard the public
forceFlush()onworker.isShutdown:Worker.shutdown()already uses when called twice.Worker.forceFlush()path thatWorker.shutdown()itself calls — the shutdown routine still runs its final flush even after it setsisShutdown = true.Test
forceFlushAfterShutdownCompletesshuts the processor down, then callsforceFlush()and verifies the returned result is already done and successful. Without the fix the result stays pending and the test blocks onjoin()until its own timeout.