Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport] Fix exception propagation in Async API methods #1485

Merged
merged 1 commit into from
Aug 21, 2024

Conversation

vbabanin
Copy link
Member

@vbabanin vbabanin commented Aug 19, 2024

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

- 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 vbabanin requested a review from rozza August 19, 2024 18:40
@vbabanin vbabanin marked this pull request as ready for review August 19, 2024 18:40
@vbabanin vbabanin changed the title Fix exception propagation in Async API methods [Backport] Fix exception propagation in Async API methods Aug 19, 2024
@vbabanin vbabanin self-assigned this Aug 19, 2024
Copy link
Member

@rozza rozza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@vbabanin vbabanin merged commit adfab5f into mongodb:5.1.x Aug 21, 2024
63 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.

2 participants