Socket: don't assign right endpoint until the connect is successful. (#53581)
authorTom Deseyn <tom.deseyn@gmail.com>
Sat, 5 Jun 2021 02:09:30 +0000 (04:09 +0200)
committerGitHub <noreply@github.com>
Sat, 5 Jun 2021 02:09:30 +0000 (19:09 -0700)
commit0d31ddb6c0fa7b9846167016734a63cdbbcc42b8
tree14e7d8f8edaf6c7dd0b52e2925236551c54ac74c
parentbc44b09721cfa060e726296c2ced87a4bf151ed2
Socket: don't assign right endpoint until the connect is successful. (#53581)

* Socket: don't assign right endpoint until the connect is successful.

'Right endpoint' must match the address family of the Socket or
we can't serialize the LocalEndPoint and RemoteEndPoint.

When multiple connect attempts are made against a DualMode Socket with
both IPv4 and IPv6 addresses, a failed attempt must not set 'right
endpoint'.

* SocketTaskExtensionsTest.EnsureMethodsAreCallable: update expected exceptions

* PR feedback

* EnsureMethodsAreCallable: move ReceiveFromAsync before ConnectAsync to avoid wildcard bind on Windows that leads to a different exception
src/libraries/System.Net.Sockets/src/System/Net/Sockets/Socket.cs
src/libraries/System.Net.Sockets/tests/FunctionalTests/Connect.cs
src/libraries/System.Net.Sockets/tests/FunctionalTests/SocketTaskExtensionsTest.cs