[release/5.0] SafeSocketHandle: avoid potential blocking of finalizer thread - #41668
Merged
Conversation
When the Socket is Disposed, it attempts to make all on-going operations abort. It does this in a loop, and decides there are no on-going operations when the reference count becomes zero and the handle gets released. SafePipeHandle holds a reference to SafeSocketHandle. This prevents the reference count to drop to zero, and causes the dispose to loop infinitly. When the Socket is disposed from the finalizer thread, it is no longer used for operations and we can skip the loop. This avoids blocking the finalizer thread when the reference count can't drop to zero.
|
Tagging subscribers to this area: @dotnet/ncl |
Contributor
Member
|
Approved for RC1 |
antonfirsov
approved these changes
Sep 1, 2020
geoffkizer
approved these changes
Sep 1, 2020
Member
Contributor
|
I don't think it's related. See: #41687 (comment) If no counter-arguments rise, I will merge this in a couple of hours. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Backport of #41508 to release/5.0
/cc @antonfirsov @tmds
Customer Impact
This fixes a critical bug, where sockets could hang the finalizer thread:
NamedPipeServerStreamorNamedPipeClientStreamundisposed on Unix. The Roslyn team faced this issue in their CI.Testing
A test has been added based on the simple repro.
Risk
Low. A finalizer run during a blocking socket operation might be problematic, but this seems to be impossible or very unlikely, since such a call implies a live socket reference, which will prevent finalizer execution.