Skip to content

follow-up: kestrel tls listener callback #62266

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

Merged

Conversation

DeagleGross
Copy link
Member

Adds a test discussed here and fixes the check limits in other test which is failing in helix.

Fixes #62172

@github-actions github-actions bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Jun 6, 2025
@@ -122,7 +122,7 @@ public async Task RunTlsClientHelloCallbackTest_WithPendingCancellation()
await writer.WriteAsync(new byte[2] { 0x03, 0x01 });
cts.Cancel();

await Assert.ThrowsAsync<OperationCanceledException>(async () => await listenerTask);
await VerifyThrowsAnyAsync(() => listenerTask, typeof(OperationCanceledException), typeof(TaskCanceledException));
Copy link
Member

Choose a reason for hiding this comment

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

Normally we just use Assert.ThrowsAnyAsync<OperationCanceledException>(...); for this

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks, i did not see that API before. refactored

@@ -66,4 +67,60 @@ await sslStream.AuthenticateAsClientAsync(new SslClientAuthenticationOptions

Assert.True(tlsClientHelloCallbackInvoked);
}

[Fact]
public async Task TlsClientHelloBytesCallback_PreCanceledToken()
Copy link
Member

Choose a reason for hiding this comment

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

There still isn't a test using the HandshakeTimeout

Copy link
Member Author

Choose a reason for hiding this comment

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

added

{
using (var connection = server.CreateConnection())
{
using (var sslStream = new SslStream(connection.Stream, false, (sender, cert, chain, errors) => true, null))
Copy link
Member

Choose a reason for hiding this comment

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

I don't think these tests should actually send any bytes over the connection. That creates a race where the timeout doesn't actually occur by the time the tls client hello is received and parsed.

Copy link
Member Author

Choose a reason for hiding this comment

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

HttpsConnectionMiddleware does catch the exception, so i am only seeing if the connection is closed after the timeout. I changed to

await connection.TransportConnection.Input.WriteAsync(new byte[] { 0x16 });
var readResult = await connection.TransportConnection.Output.ReadAsync();

// HttpsConnectionMiddleware catches the exception, so we can only check the effects of the timeout here
Assert.True(readResult.IsCompleted);

@BrennanConroy BrennanConroy merged commit 12feaab into dotnet:main Jun 7, 2025
27 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-preview6 milestone Jun 7, 2025
@DeagleGross DeagleGross deleted the dmkorolev/kestrel-tls-followup branch June 7, 2025 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TlsListenerMiddleware does not use handshake timeout
2 participants