Run CompletableResultCode completion action outside the lock - #8773
Run CompletableResultCode completion action outside the lock#8773amit306 wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8773 +/- ##
============================================
- Coverage 91.29% 91.28% -0.01%
- Complexity 10498 10533 +35
============================================
Files 1006 1008 +2
Lines 28338 28476 +138
Branches 3581 3620 +39
============================================
+ Hits 25870 25994 +124
- Misses 1675 1685 +10
- Partials 793 797 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Pull request dashboard statusWaiting on reviewers · refreshed 2026-09-13 22:30 UTC Review the latest changes. Status above doesn't look right?
|
28f8686 to
ee78eb3
Compare
We should do this, plus logging for all exceptions. Also, let's catch Exception, not Throwable. That will mean that errors (i.e. Throwables which are not Exceptions) bubble up and violate the "allOf" completion guarantee. But this seems fine and defensible. Also, your PR description is too verbose. The key details are watered down by the noise of details like which specific test cases were added, which is self explanatory from the code. Less is more. I recommend writing PR descriptions/comments yourself, rather than relying on AI. |
ee78eb3 to
4afc49d
Compare
thanks @jack-berg for comment. I have updated the code and description. Please check |
| } | ||
|
|
||
| @Test | ||
| void completionActionExceptionDoesNotEscapeWhenAlreadyComplete() { |
There was a problem hiding this comment.
Test name is inaccurate - it not asserts the exception does escape.
There was a problem hiding this comment.
yes, missed to change. rename it
| /** | ||
| * Perform an action on completion. Actions are guaranteed to be called only once. | ||
| * Perform an action on completion. Actions are guaranteed to be called only once. Actions are not | ||
| * invoked while internal locks are held. Every action runs even if an earlier one throws. Each |
There was a problem hiding this comment.
| * invoked while internal locks are held. Every action runs even if an earlier one throws. Each | |
| * invoked while internal locks are held. Every action runs even if an earlier one throws a RuntimeException. Each |
Give a hint that its only runtime exceptions that are caught
Fixes open-telemetry#8771 Signed-off-by: amit306 <amit.anand0312@gmail.com>
4afc49d to
e3c69b7
Compare
Fixes #8771
Problem
CompletableResultCode#succeed and failInternal run completion actions while holding a lock. This can cause a deadlock if two actions try to complete each other. Also, if an action throws an exception, the remaining actions are skipped and the result may never complete.
Solution
Both methods now use a shared complete method. It updates the result and copies the actions while holding the lock, then releases the lock before running them. runActions logs each exception, continues running the remaining actions, and rethrows the first exception at the end. whenComplete also uses runActions when the result is already complete.