Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions src/System.Net.Sockets/src/System/Net/Sockets/Socket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4461,16 +4461,11 @@ private void DoConnect(EndPoint endPointSnapshot, Internals.SocketAddress socket

protected virtual void Dispose(bool disposing)
{
if (!disposing)
{
return;
}

if (NetEventSource.IsEnabled)
{
try
{
NetEventSource.Info(this, $"disposing:true CleanedUp:{CleanedUp}");
NetEventSource.Info(this, $"disposing:{disposing} CleanedUp:{CleanedUp}");
NetEventSource.Enter(this);
}
catch (Exception exception) when (!ExceptionCheck.IsFatal(exception)) { }
Expand All @@ -4490,11 +4485,11 @@ protected virtual void Dispose(bool disposing)
try
{
int timeout = _closeTimeout;
if (timeout == 0)
if (timeout == 0 || !disposing)
{
// Abortive.
if (NetEventSource.IsEnabled) NetEventSource.Info(this, "Calling _handle.Dispose()");
_handle.Dispose();
_handle?.Dispose();
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ private void EventLoop()
if (context != null)
{
context.HandleEvents(_buffer[i].Events);
context = null;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ namespace System.Net.Sockets.Tests
{
public partial class DisposedSocket
{
[ActiveIssue(37044, TestPlatforms.AnyUnix)]
[Theory]
[InlineData(false)]
[InlineData(true)]
Expand All @@ -22,6 +21,7 @@ public async Task NonDisposedSocket_SafeHandlesCollected(bool clientAsync)
RetryHelper.Execute(() =>
{
GC.Collect();
GC.WaitForPendingFinalizers();
Assert.Equal(0, handles.Count(h => h.IsAlive));
});
}
Expand Down