Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix test after TcpClient change (dotnet#35721)
My change to TcpClient.ConnectAsync resulted in a sporadic test failure. ConnectAsync had been implemented in terms of Begin/EndConnect. It would call BeginConnect, and then the callback invoked when the asynchronous operation completed would call EndConnect. The very first thing EndConnect would do is check whether the TcpClient was disposed, and throw an ObjectDisposedException if it is, ignoring the actual result or failure in the callback. By changing the ConnectAsync implementation to bypass Begin/EndConnect, it's also skipping that check, and so if you dispose of the TcpClient while the operation is in flight, you'll end up with a SocketError.OperationAborted SocketException (exactly what you get from Socket) rather than an ObjectDisposedException. Since SocketException was already possible from TcpClient.ConnectAsync (and is documented as such), since we want an actual error to propagate rather than hiding it with a different one, since this is about behavior after dispose, and since this is effectively an implementation detail that was leaking out, I've opted to fix the test rather than change the implementation.
- Loading branch information