Skip to content
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

Refactor Task Socket.ConnectAsync methods to use AwaitableSocketAsyncEventArgs #787

Merged
merged 2 commits into from
Apr 27, 2020

Conversation

tmds
Copy link
Member

@tmds tmds commented Dec 12, 2019

No description provided.

@tmds tmds marked this pull request as ready for review December 12, 2019 09:03
@tmds
Copy link
Member Author

tmds commented Dec 12, 2019

@dotnet/ncl @stephentoub this PR is not finished but I'd like some early feedback.
And, some of the test failures I get don't make sense to me (yet).

It seems github doesn't allow me to mark this as Draft and still do a CI run. Can you please mark this as no-merge?

@tmds tmds changed the title Refactor Task SocketAsync.ConnectAsync methods to use AwaitableSocketAsyncEventArgs Refactor Task Socket.ConnectAsync methods to use AwaitableSocketAsyncEventArgs Dec 12, 2019
@tmds tmds force-pushed the socket_connectasync branch from 749388f to ffcc63a Compare December 12, 2019 09:07
@MihaZupan MihaZupan added the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Dec 12, 2019
@stephentoub
Copy link
Member

Thanks, @tmds. I'm concerned about doing something like this until https://github.com/dotnet/corefx/issues/39466 is addressed.

@stephentoub
Copy link
Member

I'm concerned about doing something like this until dotnet/corefx#39466 is addressed.

Although, looking at the change in more detail now, it seems you're not reusing the SAEA across sockets, only using it for that one socket? In which case maybe this isn't a big deal, because the SAEA will only be storing the same socket that it's being used with?

@tmds
Copy link
Member Author

tmds commented Dec 12, 2019

Although, looking at the change in more detail now, it seems you're not reusing the SAEA across sockets, only using it for that one socket? In which case maybe this isn't a big deal, because the SAEA will only be storing the same socket that it's being used with?

Yes, it's on the Socket where it was used to Connect, so not keeping another Socket alive.

@scalablecory scalablecory requested a review from a team December 15, 2019 01:05
@stephentoub stephentoub removed the NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) label Jan 6, 2020
@stephentoub stephentoub reopened this Jan 15, 2020
@stephentoub
Copy link
Member

@tmds, some of these test failures look relevant.

@tmds
Copy link
Member Author

tmds commented Jan 15, 2020

This test is now failing on Windows:

        [Fact]
        public async Task Ctor_NotStream_ThrowsIOException()
        {
            using (Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp))
            using (Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp))
            {
                listener.Bind(new IPEndPoint(IPAddress.Loopback, 0));
                await client.ConnectAsync(new IPEndPoint(IPAddress.Loopback, ((IPEndPoint)listener.LocalEndPoint).Port));
                Assert.Throws<IOException>(() => new NetworkStream(client));
            }
        }

Instead of throwing at the expected location, it's throwing on the ConnectAsync call above:

System.Net.Sockets.SocketException : An invalid argument was supplied.
  at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.CreateException(SocketError error, Boolean forAsyncThrow) in /_/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Tasks.cs:line 1147
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ConnectAsync(Socket socket) in /_/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Tasks.cs:line 974
   at System.Net.Sockets.Socket.ConnectAsync(EndPoint remoteEP) in /_/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Tasks.cs:line 132
   at System.Net.Sockets.SocketTaskExtensions.ConnectAsync(Socket socket, EndPoint remoteEP) in /_/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketTaskExtensions.cs:line 19
   at System.Net.Sockets.Tests.NetworkStreamTest.Ctor_NotStream_ThrowsIOException() in /_/src/libraries/System.Net.Sockets/tests/FunctionalTests/NetworkStreamTest.cs:line 41
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilderCore.cs:line 42
   at System.Net.Sockets.Tests.NetworkStreamTest.Ctor_NotStream_ThrowsIOException()
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilderCore.cs:line 42
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilderCore.cs:line 42
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilderCore.cs:line 42
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilderCore.cs:line 42
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilderCore.cs:line 42
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilderCore.cs:line 42
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilderCore.cs:line 42
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilderCore.cs:line 42
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilderCore.cs:line 42
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilderCore.cs:line 42
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilderCore.cs:line 42
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/

I'm missing the fallback for connectionless protocols that is part of BeginConnect:

internal IAsyncResult UnsafeBeginConnect(EndPoint remoteEP, AsyncCallback callback, object state, bool flowContext = false)
{
if (CanUseConnectEx(remoteEP))
{
return BeginConnectEx(remoteEP, flowContext, callback, state);
}
EndPoint endPointSnapshot = remoteEP;
var asyncResult = new ConnectAsyncResult(this, endPointSnapshot, state, callback);
// For connectionless protocols, Connect is not an I/O call.
Connect(remoteEP);
asyncResult.FinishPostingAsyncOp();
// Synchronously complete the I/O and call the user's callback.
asyncResult.InvokeCallback();
return asyncResult;
}

I'll add this and check if there are other things which may be missing.

@stephentoub
Copy link
Member

Thanks.

@tmds tmds force-pushed the socket_connectasync branch from 4745f62 to 6404854 Compare January 30, 2020 13:57
@tmds
Copy link
Member Author

tmds commented Feb 10, 2020

The latest change was to change ConnectAsync(SocketAsyncEventArgs) to make it work for UDP sockets. On Windows, the implementation was calling ConnectEx, but that isn't UDP compatible, so WSAConnect is now called instead:

                    if (CanUseConnectEx(endPointSnapshot))
                    {
                        socketError = e.DoOperationConnectEx(this, _handle);
                    }
                    else
                    {
                        // For connectionless protocols, Connect is not an I/O call.
                        socketError = e.DoOperationConnect(this, _handle);
                    }

I'm not sure if all parts of the CanUseConnectEx check apply here,. It does put us on the WSAConnect way, since the error message has changed:

System.Net.Sockets.SocketException : A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied.

with stacktrace

   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.CreateException(SocketError error, Boolean forAsyncThrow) in /_/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Tasks.cs:line 1147
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ConnectAsync(Socket socket) in /_/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Tasks.cs:line 974
   at System.Net.Sockets.Socket.ConnectAsync(EndPoint remoteEP) in /_/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Tasks.cs:line 132
   at System.Net.Sockets.SocketTaskExtensions.ConnectAsync(Socket socket, EndPoint remoteEP) in /_/src/libraries/System.Net.Sockets/src/System/Net/Sockets/SocketTaskExtensions.cs:line 19
   at System.Net.Sockets.Tests.NetworkStreamTest.Ctor_NotStream_ThrowsIOException() in /_/src/libraries/System.Net.Sockets/tests/FunctionalTests/NetworkStreamTest.cs:line 41
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilderCore.cs:line 42
   at System.Net.Sockets.Tests.NetworkStreamTest.Ctor_NotStream_ThrowsIOException()
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) in /_/src/coreclr/src/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs:line 400
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilderCore.cs:line 42
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilderCore.cs:line 42
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilderCore.cs:line 42
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilderCore.cs:line 42
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilderCore.cs:line 42
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilderCore.cs:line 42
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilderCore.cs:line 42
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilderCore.cs:line 42
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilderCore.cs:line 42
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilderCore.cs:line 42
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) in /_/src/libraries/System.Private.CoreLib/src/System/Runtime/C

From the error message I'd guess WSAENOTCONN is returned by WSAConnect, but that doesn't show up on the WSAConnect doc page. I'm lost.

I don't have a Windows machine to debug.
@dotnet/ncl can someone help me make this work on Windows?

@tmds
Copy link
Member Author

tmds commented Feb 11, 2020

@dotnet/ncl can someone help me make this work on Windows?

@karelz can someone help me with this?

@tmds
Copy link
Member Author

tmds commented Feb 27, 2020

@dotnet/ncl can someone help me make this work on Windows?

@antonfirsov maybe you can have a look?

@antonfirsov
Copy link
Member

@tmds your assumption was correct, CanUseConnectEx(...) does not return the right result on SocketAsyncEventArgs path, therefore ConnectEx is being called instead of WSAConnect.

This is even worse on master, since the original SocketAsyncEventArgs code path doesn't even try to check if it can use ConnectEx. The following code fails, which is a bug:

string path = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());

var endPoint = new UnixDomainSocketEndPoint(path);
using var server = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
using var client = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
server.Bind(endPoint);
server.Listen(1);

using var mre = new ManualResetEventSlim(false);
using var sea = new SocketAsyncEventArgs() {RemoteEndPoint = endPoint};
sea.Completed += (_, __) => mre.Set();

if (client.ConnectAsync(sea)) mre.Wait();
Assert.Equal(SocketError.Success, sea.SocketError);

@stephentoub I wonder if I should create a separate issue for this or should we just add the fix to this PR for the sake of simplicity?

@antonfirsov
Copy link
Member

antonfirsov commented Feb 27, 2020

A possible fix on my branch:
https://github.com/antonfirsov/runtime/blob/socket_connectasync-af/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.cs#L3753-L3779

I had to change the expected exception for the test case to ConnectionRefused. The original code was returning InvalidArgument because of the bug:
https://github.com/antonfirsov/runtime/blob/socket_connectasync-af/src/libraries/System.Net.Sockets/tests/FunctionalTests/UnixDomainSocketTest.cs#L107-L130

My branch is also in sync with the current master, fixed two minor conflicts from #32675. @tmds can I update this PR with all these changes?

Note that Ctor_NotStream_ThrowsIOException still fails, because Socket.SocketError is NotConnected on this line, despite of the succesful connect returning synchronously:
https://github.com/antonfirsov/runtime/blob/socket_connectasync-af/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Tasks.cs#L970

@stephentoub
Copy link
Member

stephentoub commented Feb 27, 2020

I wonder if I should create a separate issue for this

My preference would be to keep the bug fix and refactoring separate, ideally two PRs, but it could be two commits we don't squash if necessary.

@tmds
Copy link
Member Author

tmds commented Mar 2, 2020

Thanks for having a look @antonfirsov! I hope Windows CI will now pass.

ConnectAsync(saea) did not support non-stream protocols (not supported by Windows ConnectEx). With the refactoring, the Task-based API calls ConnectAsync(saea), so it needs to work also for the non-stream protocols.

@antonfirsov
Copy link
Member

@tmds a few points:

The Windows build is still failing in SocketAddress.Windows, you need _socketAddress!.Buffer here.


Note that Ctor_NotStream_ThrowsIOException still fails, because Socket.SocketError is NotConnected on this line, despite of the succesful connect returning synchronously:
https://github.com/antonfirsov/runtime/blob/socket_connectasync-af/src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.Tasks.cs#L970

Have you also tried to address this?


ConnectAsync(saea) did not support non-stream protocols (not supported by Windows ConnectEx). With the refactoring, the Task-based API calls ConnectAsync(saea), so it needs to work also for the non-stream protocols.

This means that we should enable this test now on Windows.

Additionally, I was unable to find any confirmation for the old behavior in our docs, which supports my argument that this was simply a bug. Any chance you can create a separate bugfix PR as @stephentoub suggested?

@tmds
Copy link
Member Author

tmds commented Mar 3, 2020

Additionally, I was unable to find any confirmation for the old behavior in our docs, which supports my argument that this was simply a bug. Any chance you can create a separate bugfix PR as @stephentoub suggested?

I'll rewrite the PR in 2 commits when it compiles and tests pass.

Note that Ctor_NotStream_ThrowsIOException still fails, because Socket.SocketError is NotConnected on this line, despite of the succesful connect returning synchronously:

This is another Windows-specific problem? Can you take a look?

I wonder what the SocketError is in DoOperationConnect? Is it NotConnected?

internal unsafe SocketError DoOperationConnect(Socket socket, SafeSocketHandle handle)
{
// Called for connectionless protocols.
SocketError socketError = SocketPal.Connect(handle, _socketAddress.Buffer, _socketAddress.Size);
FinishOperationSync(socketError, 0, SocketFlags.None);
return socketError;
}

@tmds
Copy link
Member Author

tmds commented Mar 10, 2020

@antonfirsov can you take a look at the remaining Windows issue?

@antonfirsov
Copy link
Member

@tmds sure, was planning to do so today.

@antonfirsov
Copy link
Member

antonfirsov commented Mar 11, 2020

@tmds congratulations, you found another Windows-specific bug without using Windows!

Explanation + possible fix + relevant test case here.

@tmds
Copy link
Member Author

tmds commented Mar 17, 2020

Explanation + possible fix + relevant test case here.

Thank you @antonfirsov ! I have included these changes. When CI passes, I will put UDP Connect(saea) into a separate PR.

@tmds
Copy link
Member Author

tmds commented Mar 17, 2020

CI shows unrelated test failures in System.Reflection.Tests.TypeTests on mono.

And System.Net.Mail.Functional.Tests has an issue on netcoreapp5.0-Windows_NT-Release-x86-CoreCLR_release-Windows.10.Amd64.Server19H1.ES.Open:

Executed on a000HEL

C:\h\w\AEAD0979\w\AC6B091D\e>call RunTests.cmd --runtime-path C:\h\w\AEAD0979\p 
----- start 17/03/2020  9:20:22,26 ===============  To repro directly: ===================================================== 
pushd C:\h\w\AEAD0979\w\AC6B091D\e\
"C:\h\w\AEAD0979\p\dotnet.exe" exec --runtimeconfig System.Net.Mail.Functional.Tests.runtimeconfig.json --depsfile System.Net.Mail.Functional.Tests.deps.json xunit.console.dll System.Net.Mail.Functional.Tests.dll -xml testResults.xml -nologo -nocolor -notrait category=IgnoreForCI -notrait category=OuterLoop -notrait category=failing -notrait category=nonnetcoreapptests -notrait category=nonwindowstests 
popd
===========================================================================================================

C:\h\w\AEAD0979\w\AC6B091D\e>"C:\h\w\AEAD0979\p\dotnet.exe" exec --runtimeconfig System.Net.Mail.Functional.Tests.runtimeconfig.json --depsfile System.Net.Mail.Functional.Tests.deps.json xunit.console.dll System.Net.Mail.Functional.Tests.dll -xml testResults.xml -nologo -nocolor -notrait category=IgnoreForCI -notrait category=OuterLoop -notrait category=failing -notrait category=nonnetcoreapptests -notrait category=nonwindowstests  
  Discovering: System.Net.Mail.Functional.Tests (method display = ClassAndMethod, method display options = None)
  Discovered:  System.Net.Mail.Functional.Tests (found 150 of 151 test cases)
  Starting:    System.Net.Mail.Functional.Tests (parallel test collections = on, max threads = 2)
----- end 17/03/2020  9:20:45,71 ----- exit code -1073740791 ----------------------------------------------------------
 17/03/2020- 9:20:45,71
 17/03/2020- 9:20:46,02
2020-03-17 09:20:46,477: INFO: 7880: run(82): main: Main thread starting 10 workers
Worker 0: starting...
Worker 1: starting...
Worker 2: starting...
Worker 3: starting...
Worker 4: starting...
Worker 5: starting...
Worker 6: starting...
Worker 7: starting...
Worker 8: starting...
Worker 9: starting...
2020-03-17 09:20:46,493: INFO: 7880: run(89): main: Beginning reading of test results.
2020-03-17 09:20:46,493: INFO: 7880: run(95): main: Uploading results in batches of size 1000
2020-03-17 09:20:46,493: INFO: 7880: run(100): main: Main thread finished queueing batches
2020-03-17 09:20:46,493: INFO: 7880: run(104): main: Main thread exiting
Searching 'C:\h\w\AEAD0979\w\AC6B091D\e\..' for log files
Found log 'C:\h\w\AEAD0979\w\AC6B091D\e\..\console.f0a3d26b.log'
Uri 'https://helixre107v0xdeko0k025g8.blob.core.windows.net/dotnet-runtime-refs-pull-787-merge-b2b1e078c6e741628f/System.Net.Mail.Functional.Tests/console.f0a3d26b.log?sv=2019-02-02&se=2020-03-27T09%3A19%3A56Z&sr=c&sp=rl&sig=lHu%2BbJDr%2Bei8G72cXctXt6vZgiegq3wqWLRAYK43ujM%3D'
Generated log list: console.f0a3d26b.log:
  https://helixre107v0xdeko0k025g8.blob.core.windows.net/dotnet-runtime-refs-pull-787-merge-b2b1e078c6e741628f/System.Net.Mail.Functional.Tests/console.f0a3d26b.log?sv=2019-02-02&se=2020-03-27T09%3A19%3A56Z&sr=c&sp=rl&sig=lHu%2BbJDr%2Bei8G72cXctXt6vZgiegq3wqWLRAYK43ujM%3D

Searching 'C:\h\w\AEAD0979\w\AC6B091D\e' for test results files
No results file found in any of the following formats: xunit, junit, trx
 17/03/2020- 9:20:46,52
2020-03-17T09:20:47.212Z	ERROR  	xunit-reporter.py	xunit-reporter(80)	main	Unable to report xunit results: no test results xml file found.

with dump file: https://helix.dot.net/api/2019-06-17/jobs/b2b1e078-c6e7-4162-8f3f-c9c1d8e8300d/workitems/System.Net.Mail.Functional.Tests/files/dotnet.exe.8892.dmp

@tmds tmds force-pushed the socket_connectasync branch from c0f2b7a to e5d3ed1 Compare April 6, 2020 15:57
[InlineData(65536)]
public async Task ConnectAsync_IPAddresses_InvalidPort_Throws_ArgumentOutOfRange(int port)
{
await Assert.ThrowsAsync<ArgumentOutOfRangeException>(() => GetSocket().ConnectAsync(new[] { IPAddress.Loopback }, port));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requires await to throw. The check could be added in the Task ConnectAsync directly.

using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp))
{
socket.Bind(new IPEndPoint(IPAddress.Loopback, 0));
socket.Listen(1);
Assert.Throws<InvalidOperationException>(() => { socket.ConnectAsync(new[] { IPAddress.Loopback }, 1); });
await Assert.ThrowsAsync<InvalidOperationException>(() => socket.ConnectAsync(new[] { IPAddress.Loopback }, 1));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This requires await to throw. The check could be added in the Task ConnectAsync directly.

@@ -167,7 +164,7 @@ public async Task ConnectGetsCanceledByDispose()
disposedException = true;
}

if (usesApm)
if (UsesApm)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exception thrown by the Task ConnectAsync methods has changed. The exceptions are now consistent with other Task-returning Socket methods.

@tmds
Copy link
Member Author

tmds commented Apr 6, 2020

With #33674 merged, I've rebased this PR.

I've added some comments with the test changes that indicate changed behavior.

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Tom.

@stephentoub stephentoub merged commit eab1d28 into dotnet:master Apr 27, 2020
@karelz karelz added this to the 5.0.0 milestone Aug 18, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants