[Backport] Fix exception propagation in Async API methods#1485
Merged
vbabanin merged 1 commit intomongodb:5.1.xfrom Aug 21, 2024
Merged
[Backport] Fix exception propagation in Async API methods#1485vbabanin merged 1 commit intomongodb:5.1.xfrom
vbabanin merged 1 commit intomongodb:5.1.xfrom
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. - 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.
Description
This PR is a partial backport of PR #1479.
CSOT-related logic is not included in this backport as the 5.1.x branch does not support CSOT. Only code changes relevant to the functionality in 5.1.x are included.
Backported Changes:
Exception handling in Async API:
Resolved an issue where exceptions thrown during thenRun, thenSupply, and related operations in the asynchronous API were not properly propagated to the completion callback. This was fixed by replacing unsafeFinish with finish, ensuring exceptions are caught and correctly passed to the completion callback, even when executed on different threads.
Async API test updates:
Updated existing Async API tests to simulate execution on separate async threads, ensuring accurate testing of the asynchronous behavior.
Local exception handling in async callbacks:
Modified the async callback to catch and handle exceptions locally. Now, exceptions are directly processed and passed as an error argument to the callback function, avoiding unintended propagation to the parent callback.
JIRA Ticket
JAVA-5562