-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Include IP information in socket.ConnectAsync(endPoint) exceptions #37685
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
Changes from all commits
b223a02
cfa3dee
aef67a5
4d14f60
b41023f
886222b
9e9cedf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -82,6 +82,20 @@ public async Task Connect_MultipleIPAddresses_Success(IPAddress listenAt) | |
| } | ||
| } | ||
|
|
||
| [OuterLoop("Slow on Windows")] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did something like using (Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
listener.Bind(new IPEndPoint(IPAddress.Loopback, 10000));
Console.WriteLine("Connecting {0}", DateTime.Now);
var clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
try
{
await clientSocket.ConnectAsync(listener.LocalEndPoint);
}
catch(Exception ex)
{
Console.WriteLine("Connect failed {0} {1}", ex.Message, DateTime.Now);
}
}and I get this on Windows 10 it seems like it takes 2s to fail. That does not seems to bad. |
||
| [Theory] | ||
| [InlineData(false)] | ||
| [InlineData(true)] | ||
| public virtual async Task Connect_WhenFails_ThrowsSocketExceptionWithIPEndpointInfo(bool useDns) | ||
| { | ||
| // Port 288 is unassigned: | ||
| // https://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.txt | ||
| EndPoint badEndpoint = useDns ? (EndPoint)new DnsEndPoint("localhost", 288) : new IPEndPoint(IPAddress.Loopback, 288); | ||
| using Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); | ||
| SocketException ex = await Assert.ThrowsAnyAsync<SocketException>(() => ConnectAsync(client, badEndpoint)); | ||
| Assert.Contains("127.0.0.1:288", ex.Message); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It may be safer to bind on anonymous port like the example above. I think that would fit better existing test pattern. |
||
| } | ||
|
|
||
| [Fact] | ||
| public async Task Connect_OnConnectedSocket_Fails() | ||
| { | ||
|
|
@@ -115,7 +129,7 @@ public async Task Connect_AfterDisconnect_Fails() | |
| } | ||
| else | ||
| { | ||
| SocketException se = await Assert.ThrowsAsync<SocketException>(() => ConnectAsync(client, new IPEndPoint(IPAddress.Loopback, port))); | ||
| SocketException se = await Assert.ThrowsAnyAsync<SocketException>(() => ConnectAsync(client, new IPEndPoint(IPAddress.Loopback, port))); | ||
| Assert.Equal(SocketError.IsConnected, se.SocketErrorCode); | ||
| } | ||
| } | ||
|
|
@@ -204,5 +218,8 @@ public ConnectTask(ITestOutputHelper output) : base(output) {} | |
| public sealed class ConnectEap : Connect<SocketHelperEap> | ||
| { | ||
| public ConnectEap(ITestOutputHelper output) : base(output) {} | ||
|
|
||
| // We should skip this since the exception creation logic is defined in SocketHelperEap. | ||
| public override Task Connect_WhenFails_ThrowsSocketExceptionWithIPEndpointInfo(bool useDns) => Task.CompletedTask; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to simply put the test function here? |
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there reason why we don't use user supplied data? If we were connecting to name resolving to multiple addresses this would log just one, right?