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

Fix exception propagation in Async API methods #1479

Merged
merged 9 commits into from
Aug 19, 2024

Conversation

vbabanin
Copy link
Member

  • 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

- 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
@vbabanin vbabanin requested a review from rozza August 14, 2024 03:29
@vbabanin vbabanin marked this pull request as ready for review August 14, 2024 03:29
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.

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 "
Copy link
Member

Choose a reason for hiding this comment

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

Should we include the v & e in the error message? Could it help debugging if this assertion ever failed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense! I have included them in the message. Thanks!

@vbabanin vbabanin requested a review from rozza August 15, 2024 23:24
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
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
Copy link
Member Author

vbabanin commented Aug 19, 2024

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:

OIDC Auth Test
Azure OIDC Auth Test
GCP OIDC Auth Test

@vbabanin vbabanin merged commit 5059158 into mongodb:master Aug 19, 2024
62 checks passed
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
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