Skip to content

Honor cancellation during SSL health checks - #41

Merged
maikebing merged 1 commit into
DotNetDiag:masterfrom
MattKotsenas:fix/ssl-handshake-cancellation-upstream
Sep 7, 2026
Merged

maikebing merged 1 commit into
DotNetDiag:masterfrom
MattKotsenas:fix/ssl-handshake-cancellation-upstream

Conversation

@MattKotsenas

Copy link
Copy Markdown

Summary

  • pass the caller's cancellation token into TLS authentication on .NET 8 and .NET 10
  • cancel and observe the .NET Standard 2.0 handshake without abandoning its task
  • add a deterministic regression test for an accepted-but-stalled TLS handshake

Fixes #40
Related: Xabaril#2485

Why

SslHealthCheck already applies cancellation while opening the TCP connection, but not during the TLS handshake. A peer can accept the connection and then remain silent, leaving the check pending beyond its configured timeout.

The .NET Standard fallback deliberately does not use WithCancellationTokenAsync. That helper returns on cancellation while abandoning the original authentication task, which can later fault unobserved when the stream is disposed. The fallback instead disposes the stream to interrupt authentication and awaits the task before translating the result to OperationCanceledException.

Validation

  • reproduced the hang against master at c9d3d49e with an accepted connection and ClientHello in flight
  • regression test passes on .NET 8 and .NET 10
  • HealthChecks.Network builds for .NET Standard 2.0, .NET 8, and .NET 10
  • HealthChecks.Network.Tests builds for .NET 8 and .NET 10
  • repository formatting checks pass for both changed projects
  • a direct probe against the compiled .NET Standard 2.0 asset completed with OperationCanceledException and no unobserved task exception

Note that X509Certificate2.Verify() is synchronous and remains outside cancellation.

MattKotsenas added a commit to MattKotsenas/MattKotsenas that referenced this pull request Sep 5, 2026
## Summary
- monitor TLS certificate validity, certificate lifetime, and HTTP
availability for every public blog domain
- use the maintained DotNetDiag health-check packages with an
operation-level timeout around third-party checks
- expose the checks through `aspire do check-public-https` and run them
daily

## Upstream follow-up
- DotNetDiag/HealthChecks#40 tracks cancellation during a stalled TLS
handshake
- Xabaril/AspNetCore.Diagnostics.HealthChecks#2485 tracks the same issue
in the original package
- DotNetDiag/HealthChecks#41 contains the proposed fix

The outer timeout remains useful because synchronous certificate
verification cannot observe cancellation.

## Scope
This is the first replacement slice for #10. It adds monitoring only and
leaves deployment resources and public DNS routing unchanged.

The scheduled workflow reads `AZURE_DEPLOYMENT_PRINCIPAL_ID` from the
repository variable used by the existing preview AppHost environment.

@maikebing maikebing left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed locally. The cancellation fix correctly passes the token to TLS authentication on NET5+ and disposes/awaits the NETSTANDARD2.0 handshake on cancellation. dotnet format passed for both projects; source builds for netstandard2.0/net8.0/net10.0; targeted regression and SSL timeout tests passed on net8.0 and net10.0. GitHub Actions are currently action_required for this fork PR, so CI did not run.

@maikebing
maikebing merged commit cde7ce4 into DotNetDiag:master Sep 7, 2026
@MattKotsenas
MattKotsenas deleted the fix/ssl-handshake-cancellation-upstream branch September 7, 2026 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SslHealthCheck ignores cancellation during the TLS handshake

2 participants