Closed karmeli87 closed 4 years ago
@karmeli87 There might be a race here between server & client. Better to add some explicit waits to ensure that the timing is consistent.
The first write call often results in this exception, which I believe you expect:
Unhandled Exception: System.IO.IOException: Unable to write data to the transport connection: An established connection was aborted by the software in your host machine.. ---> System.Net.Sockets.SocketException: An established connection was aborted by the software in your host machine.
since you're forcefully closing the connection on one end and then having the other end write to it.
You're then catching that exception and calling write again. There's a bug in SslStream where if an exception occurs while writing to the stream, it leaves the SslStream "locked", such that you get the error you mentioned. That was fixed for .NET Core 3.0 in https://github.com/dotnet/corefx/pull/36106. This really only affects the exception you get, though; you'll still get an exception from the secondary write on the failed stream, just not this NotSupportedException.
NotSupportedException:
The WriteAsync method cannot be called when another write operation is pending
while disposing after writing to closed stream.Failed both on Ubuntu 18.04 and Windows 10 with dotnet runtime 2.2.3 and sdk 2.2.105 with the exception:
This is the code to repo the issue:
There are few interesting things here:
IOException
(To me this is the actual bug)StreamWriter
uses theStreamWriter(Stream)
constructor. In that case there is no exception at all (not sure ifIOException
would be also expect).