You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Remove Socket finalizer and ensure SafeSocketHandle finalization works correctly #43383
The Socket class has a finalizer, but it shouldn't need to have one. It should be able to rely on the finalizer of SafeSocketHandle to handle finalization when necessary, now that the logic in SafeSocketHandle is reliable as of 5.0.
Having both of these objects be finalizable is problematic since we can't control the order in which their finalizers are called, and this may lead to unexpected behavior. It's also just unneeded overhead in the GC.
I tested removing the finalizer, and everything works fine on Windows. However, on Linux the SafeSocketHandle is not properly collected. I believe this is because there's a reference to the SafeSocketHandle held (indirectly) by the SocketAsyncEngine dictionary. We probably need to make this a weak reference, or otherwise change the code so that the reference is not held.
Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.
This issue will now be closed since it had been marked no-recent-activity but received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.
Activity
tmds commentedon Oct 29, 2020
It would be nice if we can get rid of the finalizer on Socket. It is not causing any issues afaik.
dotnet-policy-service commentedon Nov 12, 2025
Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process.
This process is part of our issue cleanup automation.
dotnet-policy-service commentedon Nov 26, 2025
This issue will now be closed since it had been marked
no-recent-activitybut received no further activity in the past 14 days. It is still possible to reopen or comment on the issue, but please note that the issue will be locked if it remains inactive for another 30 days.