Fix exception propagation in Async API methods#1479
Merged
vbabanin merged 9 commits intomongodb:masterfrom Aug 19, 2024
Merged
Conversation
- Resolve an issue where exceptions thrown during thenRun, thenSupply, and related operations in the asynchronous API were not properly propagated to the completion callback. This issue was addressed by replacing `unsafeFinish` with `finish`, ensuring that exceptions are caught and correctly passed to the completion callback when executed on different threads. - Update existing Async API tests to ensure they simulate separate async thread execution. JAVA-5562
JAVA-5562
JAVA-5562
JAVA-5562
rozza
requested changes
Aug 14, 2024
Member
rozza
left a comment
There was a problem hiding this comment.
Looks really good.
However, one test in evergreen seems to be failing: com.mongodb.reactivestreams.client.unified.LoadBalancerTest which needs investigation before I can LGTM
| try { | ||
| this.unsafeFinish(value, (v, e) -> { | ||
| if (!callbackInvoked.compareAndSet(false, true)) { | ||
| throw new AssertionError("Callback has been already completed. It could happen " |
Member
There was a problem hiding this comment.
Should we include the v & e in the error message? Could it help debugging if this assertion ever failed?
Member
Author
There was a problem hiding this comment.
Makes sense! I have included them in the message. Thanks!
Modify the async callback to catch and handle exceptions locally. Exceptions are now directly processed and passed as an error argument to the callback function, avoiding propagation to the parent callback. JAVA-5562
…nvoked twice when an exception occurs. JAVA-5562
JAVA-5562
Member
Author
|
The Async API is currently utilized in the OIDC, Authenticator, and InternalStreamConnection components. I have conducted additional OIDC tests to verify the changes, and all results are green: |
vbabanin
added a commit
to vbabanin/mongo-java-driver
that referenced
this pull request
Aug 19, 2024
- Resolve an issue where exceptions thrown during thenRun, thenSupply, and related operations in the asynchronous API were not properly propagated to the completion callback. This issue was addressed by replacing `unsafeFinish` with `finish`, ensuring that exceptions are caught and correctly passed to the completion callback when executed on different threads. - Update existing Async API tests to ensure they simulate separate async thread execution. - Modify the async callback to catch and handle exceptions locally. Exceptions are now directly processed and passed as an error argument to the callback function, avoiding propagation to the parent callback. - Move `callback.onResult` outside the catch block to ensure it's not invoked twice when an exception occurs. JAVA-5562
vbabanin
added a commit
that referenced
this pull request
Aug 21, 2024
- Resolve an issue where exceptions thrown during thenRun, thenSupply, and related operations in the asynchronous API were not properly propagated to the completion callback. This issue was addressed by replacing `unsafeFinish` with `finish`, ensuring that exceptions are caught and correctly passed to the completion callback when executed on different threads. - Update existing Async API tests to ensure they simulate separate async thread execution. - Modify the async callback to catch and handle exceptions locally. Exceptions are now directly processed and passed as an error argument to the callback function, avoiding propagation to the parent callback. - Move `callback.onResult` outside the catch block to ensure it's not invoked twice when an exception occurs. JAVA-5562
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.
Resolve an issue where exceptions thrown during thenRun, thenSupply, and related operations in the asynchronous API were not properly propagated to the completion callback. This issue was addressed by replacing
unsafeFinishwithfinish, ensuring that exceptions are caught and correctly passed to the completion callback when executed on different threads.Update existing Async API tests to ensure they simulate separate async thread execution.
JAVA-5562