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

Recover ReentrantSemaphore after JTF throws an exception #844

Merged
merged 3 commits into from May 5, 2021

Conversation

AArnott
Copy link
Member

@AArnott AArnott commented May 4, 2021

We already had a try/finally block, but it assumed JTF.RunAsync itself wouldn't throw an exception. In some cases it does throw an exception (OutOfMemoryException for example) and it's critical to avoiding deadlocks later on that we exit the semaphore we entered in this case so we do not deadlock later.

I'm not adding an automated test for this because JTF offers no extensibility point that would allow me to instrument a failure into the scenario (which is a good thing, since it means JTF is more reliable).

Fixes #843

We already had a try/finally block, but it assumed JTF.RunAsync itself wouldn't throw an exception. In some cases it *does* throw an exception (`OutOfMemoryException` for example) and it's critical to avoiding deadlocks later on that we exit the semaphore we entered in this case so we do not deadlock later.

Fixes microsoft#843
@AArnott AArnott added this to the v17.0 milestone May 4, 2021
@AArnott AArnott requested a review from jdrobison May 4, 2021 21:45
@AArnott AArnott self-assigned this May 4, 2021
Copy link
Member

@ryanmolden ryanmolden left a comment

Choose a reason for hiding this comment

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

Looks reasonable, though I don't have a ton of context on this code, so if all that was done (and all it appears was done) was expanding the try scopes to include the JTF calls we treated as no-fail in the past, looks good. If more complex changes were done that escaped my eyes...well, may the odds be forever in your favor :)

@AArnott AArnott force-pushed the improveSemaphoreReliability branch from 9a5e278 to 3adfb9d Compare May 4, 2021 22:41
@AArnott AArnott force-pushed the improveSemaphoreReliability branch from 3adfb9d to 9f2c0e3 Compare May 4, 2021 22:44
@AArnott AArnott merged commit 87ef3de into microsoft:main May 5, 2021
@AArnott AArnott deleted the improveSemaphoreReliability branch May 5, 2021 05:13
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.

ReentrantSemaphore may deadlock after JTF.RunAsync throws an exception before invoking delegate
3 participants