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

Additional QuicConnectionOptions #94211

Merged

Conversation

rzikm
Copy link
Member

@rzikm rzikm commented Oct 31, 2023

Closes #72984.
Closes #70090.

Adds:

  • KeepAliveInterval - sending ping frames to prevent the connection from idling out. (we may want to add the same property on QuicConnection itself so that users can turn pings on/off according to their needs)
  • flow-control limits (max_data) - stream-level limits will have effect only with newer MsQuic having Support setting flow control limits for individual stream types microsoft/msquic#3948. 2.4+ should be it
  • HandshakeTimeout - kills the connection if the handshake is not established in the given amount of time
    • ServerOptionsCallback still has 10s timeout as before, once the callback returns, the timeout value from the options is applied.
      The client times out as well.
    • Timeouts lead to peer receiving UserCanceled TLS Alert which is weird but is not against the spec, although getting CONNECTION_CLOSE with APPLICATION_ERROR would be more expected.

Other improvements:

  • if the client terminates the connection during the handshake, CancellationToken passed to ServerOptionsCallback fires as well.
  • Fix property names in ArgumentExceptions thrown from connection options validation (previously it put the message instead of the parameter name)

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, 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 ghost assigned rzikm Oct 31, 2023
@ghost
Copy link

ghost commented Oct 31, 2023

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

Issue Details

Closes #72984.

Draft for now until we go through API review.

Author: rzikm
Assignees: -
Labels:

new-api-needs-documentation, area-System.Net.Quic

Milestone: -

@rzikm rzikm force-pushed the 72984-API-Proposal-Additional-QuicConnectionOptions branch from 8791161 to 96dccbf Compare November 15, 2023 12:42
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.

I know it's a draft, but I might not have time to review this properly later.

@rzikm rzikm marked this pull request as ready for review November 16, 2023 14:27
@rzikm rzikm requested a review from a team November 16, 2023 14:27
@rzikm
Copy link
Member Author

rzikm commented Nov 16, 2023

/azp run runtime-libraries-coreclr outerloop

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@@ -93,6 +105,9 @@ static async ValueTask<QuicConnection> StartConnectAsync(QuicClientConnectionOpt
private readonly ValueTaskSource _connectedTcs = new ValueTaskSource();
private readonly ValueTaskSource _shutdownTcs = new ValueTaskSource();

private readonly CancellationTokenSource _shutdownCancellationTokenSource = new CancellationTokenSource();
Copy link
Member

Choose a reason for hiding this comment

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

I think we might need to dispose _shutdownCancellationTokenSource?
Also, the naming confuses me... It implies the cancellation of the connection's shutdown, but it's not, it's for cancelling the handshake in the Listener, right? (and it also means it's not needed on the client side?)

Copy link
Member Author

Choose a reason for hiding this comment

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

It is used only for listener to cancel the connection options callback if peer closes the connection before the handshake. I did not find a way to put the CTS outside QuicConnection.

I will try to come up with a better name

Copy link
Member

Choose a reason for hiding this comment

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

What do we do in SslStream case? Do we also react and cancel user callback when the client kills handshake in the meantime?

Copy link
Member Author

Choose a reason for hiding this comment

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

With sslstream we don't check for client-side activity while invoking the callback. We would have to always have a pending read on the inner stream and check for errors there. SslStream passes in the same token as to AuthenticateAsClientAsync.

Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed to ConnectionShutdownToken and added a comment

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.

In general looks good. I think the last contentious thing is the _shutdownCancellationTokenSource.

Exception exception = await AssertThrowsQuicExceptionAsync(QuicError.ConnectionTimeout, async () => await listener.AcceptConnectionAsync());
Assert.Equal(SR.Format(SR.net_quic_handshake_timeout, QuicDefaults.HandshakeTimeout), exception.Message);
QuicClientConnectionOptions clientOptions = CreateQuicClientOptions(listener.LocalEndPoint);
clientOptions.HandshakeTimeout = clientShorterTimeout ? TimeSpan.FromSeconds(2) : TimeSpan.FromSeconds(20);
Copy link
Member

Choose a reason for hiding this comment

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

I'm pretty sure this will eventually pop-up in CI report. Especially if you're asserting specific types of exception that should happen only in certain order of events depending on this timing.

But we can wait until we see it.

@@ -93,6 +105,9 @@ static async ValueTask<QuicConnection> StartConnectAsync(QuicClientConnectionOpt
private readonly ValueTaskSource _connectedTcs = new ValueTaskSource();
private readonly ValueTaskSource _shutdownTcs = new ValueTaskSource();

private readonly CancellationTokenSource _shutdownCancellationTokenSource = new CancellationTokenSource();
Copy link
Member

Choose a reason for hiding this comment

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

What do we do in SslStream case? Do we also react and cancel user callback when the client kills handshake in the meantime?

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.

:shipit:
Thank you!

@rzikm
Copy link
Member Author

rzikm commented Nov 28, 2023

All CI failures are known build failures

@rzikm rzikm requested a review from CarnaViire November 28, 2023 13:57
@ManickaP
Copy link
Member

BTW, I assume this also fixes #70090

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

@rzikm rzikm merged commit 563664e into dotnet:main Nov 29, 2023
104 of 109 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Dec 30, 2023
@karelz karelz added this to the 9.0.0 milestone May 14, 2024
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.

[API Proposal]: Additional QuicConnectionOptions [API Proposal]: Quic connection keep alive
4 participants