-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
SslStream.ReadAsyncInternal() throws misleading exception if stream is disposed while reading #78586
Comments
Tagging subscribers to this area: @dotnet/ncl, @vcsjones Issue DetailsDescriptionIf
The exception message claims that "ReadAsyncInternal() was called when another read operation is pending", but this is misleading, since there were not concurrent calls to runtime/src/libraries/System.Net.Security/src/System/Net/Security/SslStream.IO.cs Lines 50 to 63 in 6ddd06c
runtime/src/libraries/System.Net.Security/src/System/Net/Security/SslStream.IO.cs Lines 763 to 769 in 6ddd06c
For customers trying to debug this issue, it would be very helpful if Maybe a code change like this? if (Interlocked.Exchange(ref _nestedRead, 1) == 1)
{
ThrowIfExceptionalOrNotAuthenticated();
throw new NotSupportedException(SR.Format(SR.net_io_invalidnestedcall, "read"));
} Reproduction StepsYou should be able to repro this by concurrently calling Expected behavior
Actual behavior
Regression?No Known WorkaroundsNo response Configuration.NET Runtime 7.0.0 Other informationNo response
|
I look at it more closely it may be something different. I changed the value we set in closing but I still saw errors about concurrent read. Also since I have debug version of HTTP, I saw occasional I feel we can still make improvements in |
It'd be challenging for us to make any strong guarantees about the thread-safety of using an SslStream and Dispose'ing it concurrently. People do and will, whether we document it as safe to do or not (we don't), so we should strive to minimize the impact of doing so in the name of defense in depth, but I suspect we'll still have a tail of issues that remain. |
closed by #79329 |
Description
If
SslStream
is disposed while there is a concurrent call toReadAsyncInternal()
, a misleading exception may be thrown:The exception message claims that "ReadAsyncInternal() was called when another read operation is pending", but this is misleading, since there were not concurrent calls to
ReadAsyncInternal()
. This exception message is raised due to the following codepaths:runtime/src/libraries/System.Net.Security/src/System/Net/Security/SslStream.IO.cs
Lines 50 to 63 in 6ddd06c
runtime/src/libraries/System.Net.Security/src/System/Net/Security/SslStream.IO.cs
Lines 763 to 769 in 6ddd06c
For customers trying to debug this issue, it would be very helpful if
ReadAsyncInternal()
could throwObjectDisposedException
in this case. This makes it clear the issue is dispose during read, not concurrent reads.Maybe a code change like this?
Reproduction Steps
You should be able to repro this by concurrently calling
Read()
andDispose()
in a loop until you trigger the race condition. Alternatively, you can use the repro I created for the Azure SDK (which has a bug where it callsDispose()
concurrently during aRead()
):Azure/azure-sdk-for-net#32577
Expected behavior
SslStream
throwsObjectDisposedException
Actual behavior
SslStream
throwsNotSupportedException
Regression?
No
Known Workarounds
No response
Configuration
.NET Runtime 7.0.0
Windows 10
x64
Other information
No response
The text was updated successfully, but these errors were encountered: