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

Fix exception thrown when MsQuicStream write direction is locally aborted or canceled #67753

Merged
merged 5 commits into from
Apr 12, 2022

Conversation

rzikm
Copy link
Member

@rzikm rzikm commented Apr 8, 2022

Fixes #67612.

The issue with the original code was that when MsQuicStream s write direction was locally aborted, subsequent WriteAsync calls threw OperationCanceledException which does not make sense since the associated CancellationToken was not expired (or wasn't even cancellable for that matter).

This PR changes that behavior to throw QuicOperationAbortedException instead, which is in line with #55619.

Also, when a WriteAsync call si canceled (either during actual write or pre-canceled), subsequent (non-pre-canceled) operations now throw QuicOperationAbortedException like we do on the reading side of the stream.

@ghost
Copy link

ghost commented Apr 8, 2022

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

Issue Details

Fixes #67612.

The issue with the original code was that when MsQuicStream s write direction was locally aborted, subsequent WriteAsync calls threw OperationCanceledException instead of QuicOperationAbortedException. The original exception did not make sense since the associated CancellationToken was not expired (or wasn't even cancellable for that matter). The new exception is more in line with #55619

Author: rzikm
Assignees: -
Labels:

area-System.Net.Quic

Milestone: -

Copy link
Member

@ManickaP ManickaP left a comment

Choose a reason for hiding this comment

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

One question, otherwise LGTM, thanks!

@@ -376,7 +378,7 @@ private CancellationTokenRegistration HandleWriteStartState(bool emptyBuffer, Ca
throw new QuicStreamAbortedException(_state.SendErrorCode);
}

throw new OperationCanceledException(SR.net_quic_sending_aborted);
throw new QuicOperationAbortedException();
Copy link
Member

Choose a reason for hiding this comment

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

Any reason for not providing a message here?

Copy link
Member Author

Choose a reason for hiding this comment

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

no reason, I forgot to put it there when copying

@rzikm
Copy link
Member Author

rzikm commented Apr 11, 2022

Looks like this will not be so simple, the stream conformance tests are failing

[xUnit.net 00:00:33.05]     System.Net.Quic.Tests.MsQuicQuicStreamConformanceTests.ReadWriteAsync_PrecanceledOperations_ThrowsCancellationException [FAIL]
  Failed System.Net.Quic.Tests.MsQuicQuicStreamConformanceTests.ReadWriteAsync_PrecanceledOperations_ThrowsCancellationException [17 ms]
  Error Message:
   Assert.Throws() Failure
Expected: typeof(System.OperationCanceledException)
Actual:   typeof(System.Net.Quic.QuicOperationAbortedException): Sending has already been aborted on the stream
---- System.Net.Quic.QuicOperationAbortedException : Sending has already been aborted on the stream
  Stack Trace:
     at System.Net.Quic.Implementations.MsQuic.MsQuicStream.HandleWriteStartState(Boolean emptyBuffer, CancellationToken cancellationToken) in C:\source\runtime\src\libraries\System.Net.Quic\src\System\Net\Quic\Implementations\MsQuic\MsQuicStream.cs:line 332
   at System.Net.Quic.Implementations.MsQuic.MsQuicStream.WriteAsync(ReadOnlyMemory`1 buffer, Boolean endStream, CancellationToken cancellationToken) in C:\source\runtime\src\libraries\System.Net.Quic\src\System\Net\Quic\Implementations\MsQuic\MsQuicStream.cs:line 310
   at System.IO.Tests.StreamConformanceTests.<>c__DisplayClass54_0.<<ValidatePrecanceledOperations_ThrowsCancellationException>b__3>d.MoveNext() in C:\source\runtime\src\libraries\Common\tests\StreamConformanceTests\System\IO\StreamConformanceTests.cs:line 515
--- End of stack trace from previous location ---
----- Inner Stack Trace -----

@rzikm
Copy link
Member Author

rzikm commented Apr 11, 2022

/azp run runtime-libraries-coreclr outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@rzikm rzikm requested a review from ManickaP April 11, 2022 08:42
@rzikm
Copy link
Member Author

rzikm commented Apr 11, 2022

It seems we need to change the exception after canceling WriteAsync, after consulting with @CarnaViire, I followed what we do on the read side of the stream to make the behavior consistent. I updated the PR description to reflect this.

@ManickaP can you please review again?

@rzikm rzikm changed the title Fix exception thrown when MsQuicStream write direction is locally aborted Fix exception thrown when MsQuicStream write direction is locally aborted or canceled Apr 12, 2022
Copy link
Member

@ManickaP ManickaP left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@rzikm
Copy link
Member Author

rzikm commented Apr 12, 2022

The failing test is unrelated (System.Security.Cryptography.Pkcs.Tests.SignedCmsTests.AddSignerWithNegativeSerial)

@rzikm rzikm merged commit 42044c6 into dotnet:main Apr 12, 2022
@ghost ghost locked as resolved and limited conversation to collaborators May 12, 2022
@karelz karelz added this to the 7.0.0 milestone Jul 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
3 participants