-
Notifications
You must be signed in to change notification settings - Fork 5k
TcpListener regression: SocketException at InputShare app #41585
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
Comments
Tagging subscribers to this area: @dotnet/ncl |
There is a big inconsistency between the various code paths (Sync, APM, EAP/Task) when disposing a socket during accept. Only the APM path seems to throw
Repro: add the following test to [Fact]
public async Task AcceptAsync_WhenDisposed_ThrowsObjectDisposedException()
{
Socket listen = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
int port = listen.BindToAnonymousPort(IPAddress.Loopback);
listen.Listen(1);
using Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
Task<Socket> acceptTask = AcceptAsync(listen);
// give some time for the OS calls:
await Task.Delay(100);
listen.Dispose();
_ = client.ConnectAsync(new IPEndPoint(IPAddress.Loopback, port));
Exception ex = await Assert.ThrowsAnyAsync<Exception>(() => acceptTask);
string socketErrorCode = ex is SocketException sx ? $"({sx.ErrorCode})" : "";
_output.WriteLine($"{ex.GetType()} | {ex.Message} {socketErrorCode}");
} @geoffkizer @scalablecory should we synchronize the behavior for 5.0? If yes, should we map to |
It's expected for Task-based async to throw with Do we have a regression from 3.x or is this just things being different? |
@scalablecory if my understanding is correct, with APM there is no way / no point to distinguish those cases from API users perspective. The exception is always being thrown when runtime/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.cs Lines 3549 to 3555 in 2ba6515
From the perspective of how APM API-s work, it seems actually logical to throw Since we delegate the exception throwing logic from Maybe I'm wrong here and exceptions should not be consistent, but we need a decision ASAP. If we can't clarify this, maybe we should just revert #40476 to prevent the breaking change. The inconsistency between the implementation ( |
Making this work like 3.1 is easy enough, we should just add the ThrowIfDisposed check to EndAccept. I agree that it would be nice to clean up our exceptions to be more consistent here -- we should look at that for 6.0. But right now let's just address this particular issue. |
What's particularly weird about this is that TcpListener does not actually implement IDisposable, yet we throw ObjectDisposedException anyway. Strange. |
@antonfirsov @karelz Just want to confirm will the fix go into RC1 branch? I saw you have mentioned in the PR that the fix will not included in RC1 and document it as known issue. |
@jiangzeng01 unfortunately the change will land in RC2 only. |
@jiangzeng01 that is correct, this should be only documented as a known issue for RC1. |
Uh oh!
There was an error while loading. Please reload this page.
Application Name: Input Share
OS: Windows 10 RS5
CPU: X64
.NET Build Number: 5.0.100-rc.1.20430.2
Verify Scenarios:
1). Windows 10 RS5 X64 + .NET Core SDK build 5.0.100-rc.1.20430.2: Fail
2). Windows 10 RS5 X64 + .NET Core SDK build 5.0.100-preview.8 : Pass
3). Windows 10 RS5 X64 + .NET Core SDK build 3.1.300 Pass
DevDiv bug:
https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems/edit/1188270
Minimal Repro App:
https://github.com/jiangzeng01/socketexceptionrepro.git
Findings :
When we stop TcpListener, it BeingAccesSocket call back, it gets different exception in net5 rc1, it makes the app crash :
We start listener like this :
We stop like this :
Exception from InputShare app:
CC @dotnet-actwx-bot
The text was updated successfully, but these errors were encountered: