Skip to content

[release/5.0] SafeSocketHandle: avoid potential blocking of finalizer thread - #41668

Merged
antonfirsov merged 10 commits into
release/5.0from
backport/pr-41508-to-release/5.0
Sep 2, 2020
Merged

[release/5.0] SafeSocketHandle: avoid potential blocking of finalizer thread#41668
antonfirsov merged 10 commits into
release/5.0from
backport/pr-41508-to-release/5.0

Conversation

@github-actions

@github-actions github-actions Bot commented Sep 1, 2020

Copy link
Copy Markdown
Contributor

Backport of #41508 to release/5.0

/cc @antonfirsov @tmds

Customer Impact

This fixes a critical bug, where sockets could hang the finalizer thread:

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.

tmds added 10 commits September 1, 2020 12:46
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.
@ghost

ghost commented Sep 1, 2020

Copy link
Copy Markdown

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

@ericstj
ericstj requested review from a team, antonfirsov and karelz September 1, 2020 16:17
@danmoseley danmoseley added the Servicing-consider Issue for next servicing release review label Sep 1, 2020
@marklio marklio added tenet-reliability Reliability/stability related issue (stress, load problems, etc.) and removed tenet-reliability Reliability/stability related issue (stress, load problems, etc.) labels Sep 1, 2020
@jamshedd jamshedd added Servicing-approved Approved for servicing release and removed Servicing-consider Issue for next servicing release review labels Sep 1, 2020
@antonfirsov

antonfirsov commented Sep 1, 2020

Copy link
Copy Markdown
Contributor

Test failures are unrelated: #41494 #41506 #41687 #41506

@jamshedd jamshedd modified the milestones: 5.0.0 Preview 8, 5.0.0 rc1 Sep 1, 2020
@jamshedd

jamshedd commented Sep 1, 2020

Copy link
Copy Markdown
Member

Approved for RC1

@tmds

tmds commented Sep 2, 2020

Copy link
Copy Markdown
Member

@wfurt pointed out that #41687 may be related.

@antonfirsov

Copy link
Copy Markdown
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.

@antonfirsov
antonfirsov merged commit 1338dd3 into release/5.0 Sep 2, 2020
@jkotas
jkotas deleted the backport/pr-41508-to-release/5.0 branch September 4, 2020 04:08
@karelz karelz modified the milestones: 5.0.0 rc1, 5.0.0 Sep 9, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-System.Net.Sockets Servicing-approved Approved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants