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

[QUIC] Add QuicStream.WaitForWriteCompletionAsync #58236

Merged

Conversation

JamesNK
Copy link
Member

@JamesNK JamesNK commented Aug 27, 2021

Fixes #58229

@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost
Copy link

ghost commented Aug 27, 2021

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

Issue Details

Fixes #58229

Author: JamesNK
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.

Some small questions, otherwise looks good!
Thanks!

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!

@CarnaViire
Copy link
Member

Just an FYI that I'm also looking at this, will post my review today

@@ -1040,6 +1145,12 @@ private static uint HandleEventShutdownComplete(State state, ref StreamEvent evt

shouldReadComplete = CleanupReadStateAndCheckPending(state, ReadState.ReadsCompleted);

if (state.ShutdownWriteState == ShutdownWriteState.None)
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure this state is expected here? As you've mentioned in comment for HandleEventSendShutdownComplete, by the time we receive SHUTDOWN_COMPLETE event, we should either completed ShutdownWriteState already, or it is a connection close, which is handled separately in HandleEventConnectionClose. I think we may leave the logic here, but guard it with Debug.Assert... what do you think?

Copy link
Member

Choose a reason for hiding this comment

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

Even as a fallback, I think it is especially strange to complete it successfully here... IMO successful completion should only happen in HandleEventSendShutdownComplete.

Copy link
Member Author

Choose a reason for hiding this comment

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

There is one situation where you can get to this point without HandleEventSendShutdownComplete: if the stream is unidirectional and there are no writes.

Perhaps WaitForWriteCompleteAsync should error if it is called for this type of stream. I'm going to add that as a TODO comment. I'll also explain it in the logic inside HandleEventShutdownComplete. The exact behavior can be figured out in .NET 7.

Assert.Equal(1, received);
Assert.True(serverStream.ReadsCompleted);

long sendAbortErrorCode = await waitForAbortTcs.Task;
Copy link
Member

Choose a reason for hiding this comment

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

Could that be just

var ex = await Assert.ThrowsAsync<QuicStreamAbortedException>(() => serverStream.WaitForWriteCompletionAsync());
Assert.Equal(ExpectedErrorCode, ex.ErrorCode);

? (Here and below)

Copy link
Member Author

Choose a reason for hiding this comment

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

I want to test the wait part of WaitForWriteCompletionAsync

[Fact]
public async Task WaitForWriteCompletionAsync_ClientReadAborted_Throws()
{
const int ExpectedErrorCode = 0xfffffff;
Copy link
Member

Choose a reason for hiding this comment

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

I wanted to comment that we use the same constant as a default error code on Dispose, but we actually use 0xffffffff, not 0xfffffff 😁

Copy link
Member

Choose a reason for hiding this comment

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

We might want to choose a different number, diff between 7x f and 8x f is too small to be noticeable.

Copy link
Member

Choose a reason for hiding this comment

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

Assert.Equal will show decimal representation, so it will be easier to distinguish... but it will be harder to catch in the future if some other test will accidentally use 8xf

Copy link
Member Author

Choose a reason for hiding this comment

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

I copied the value from a different test. IMO lets leave it as is for now, and if you want to change all instances of this value then it can be done in a future PR.

@CarnaViire
Copy link
Member

I see that new tests are failing for Mock. Aborts didn't work properly on Mocks before, and I guess the changes didn't fix them fully... 😢 I wonder if we really want to invest into fixing Mock at this point. I would vote for no. Thoughts? @ManickaP @geoffkizer

@ManickaP
Copy link
Member

I see that new tests are failing for Mock. Aborts didn't work properly on Mocks before, and I guess the changes didn't fix them fully... cry I wonder if we really want to invest into fixing Mock at this point.

We can disable the tests for mocks specifically, we have a precedent for that. So unless it's super obvious and easy to fix, I wouldn't put much effort in it.

@geoffkizer
Copy link
Contributor

We can disable the tests for mocks specifically, we have a precedent for that. So unless it's super obvious and easy to fix, I wouldn't put much effort in it.

+1 to this

Once 6.0 is done we should discuss whether to keep Mock at all. But for now let's just disable specific test and not make any major changes.

@JamesNK
Copy link
Member Author

JamesNK commented Aug 31, 2021

We can disable the tests for mocks specifically, we have a precedent for that. So unless it's super obvious and easy to fix, I wouldn't put much effort in it.

It was super obvious and easy to fix.

@JamesNK
Copy link
Member Author

JamesNK commented Aug 31, 2021

All PR feedback has been applied. I'm creating a release/6.0 (RC2) backport issue with details about the change for @adityamandaleeka to take to tactics tomorrow.

Hopefully there are no more changes. If there is something then I can apply it to both PRs.

@JamesNK JamesNK force-pushed the jamesnk/quic-waitforwritecompletion branch from 7fdedf2 to 75be833 Compare August 31, 2021 02:42
@JamesNK
Copy link
Member Author

JamesNK commented Aug 31, 2021

/backport to release/6.0

@github-actions
Copy link
Contributor

Started backporting to release/6.0: https://github.com/dotnet/runtime/actions/runs/1184544908

@karelz
Copy link
Member

karelz commented Aug 31, 2021

Unrelated test failure (likely) #734 - see log

    System.Security.Cryptography.Rsa.Tests.SignVerify_Span.InvalidKeySize_DoesNotInvalidateKey [FAIL]
      Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException : Unknown error (0xc0000001)
      Stack Trace:
        /_/src/libraries/Common/src/Internal/Cryptography/CngCommon.SignVerify.cs(80,0): at Internal.Cryptography.CngCommon.TrySignHash(SafeNCryptKeyHandle keyHandle, ReadOnlySpan`1 hash, Span`1 signature, AsymmetricPaddingMode paddingMode, Void* pPaddingInfo, Int32& bytesWritten)
        /_/src/libraries/Common/src/System/Security/Cryptography/RSACng.SignVerify.cs(125,0): at System.Security.Cryptography.RSACng.TrySignHash(ReadOnlySpan`1 hash, Span`1 destination, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding, Int32& bytesWritten)
        /_/src/libraries/System.Security.Cryptography.Algorithms/src/System/Security/Cryptography/RSA.cs(206,0): at System.Security.Cryptography.RSA.TrySignData(ReadOnlySpan`1 data, Span`1 destination, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding, Int32& bytesWritten)
        /_/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/SignVerify.netcoreapp.cs(11,0): at System.Security.Cryptography.Rsa.Tests.SignVerify_Span.<>c__DisplayClass0_0.<SignData>b__0(Byte[] dest)
        /_/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/SignVerify.netcoreapp.cs(27,0): at System.Security.Cryptography.Rsa.Tests.SignVerify_Span.TryWithOutputArray(Func`2 func)
        /_/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/SignVerify.netcoreapp.cs(11,0): at System.Security.Cryptography.Rsa.Tests.SignVerify_Span.SignData(RSA rsa, Byte[] data, HashAlgorithmName hashAlgorithm, RSASignaturePadding padding)
        /_/src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/RSA/SignVerify.cs(114,0): at System.Security.Cryptography.Rsa.Tests.SignVerify.InvalidKeySize_DoesNotInvalidateKey()

runtime-staging failures seem to be unrelated, rerunning.

@JamesNK
Copy link
Member Author

JamesNK commented Aug 31, 2021

/backport to release/6.0

@github-actions
Copy link
Contributor

Started backporting to release/6.0: https://github.com/dotnet/runtime/actions/runs/1185710989

Copy link
Member

@CarnaViire CarnaViire 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!

@karelz
Copy link
Member

karelz commented Aug 31, 2021

dotnet-linker-tests failure - hit 120min timeout. Rerunning.

@adityamandaleeka adityamandaleeka merged commit 629f60e into dotnet:main Aug 31, 2021
@adityamandaleeka
Copy link
Member

Thanks everyone!

@karelz karelz added this to the 7.0.0 milestone Sep 1, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Oct 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

QUIC: Add API to allow detecting when peer aborts receive
8 participants