Skip to content

Fix socket-bound TLS post-handshake authentication progress - #136475

Merged
rzikm merged 1 commit into
dotnet:mainfrom
rzikm:rzikm/tls-second-handshake-timeout
Oct 28, 2026
Merged

rzikm merged 1 commit into
dotnet:mainfrom
rzikm:rzikm/tls-second-handshake-timeout

Conversation

@rzikm

@rzikm rzikm commented Oct 26, 2026

Copy link
Copy Markdown
Member

Fix a post-handshake authentication race that can leave a socket-bound TLS session waiting indefinitely even though the peer has finished the exchange.

The first native handshake call currently invokes SSL_peek, which can process a fast peer's entire response. The driver then returns NeedMoreData because it considers that call request-flushing only. Subsequent calls wait for socket readability, but the response has already been consumed.

Separate request emission from response processing: skip the peek while flushing the initial certificate request, then retain it on subsequent calls. This preserves write-backpressure retries, handshake completion checks, and certificate-validation suspension. Extend the existing TLS 1.2/1.3 theory with idle-peer cases to verify that sending the request alone does not prematurely complete authentication. No timeout increases or test skips.

Validation

  • Linux clr+libs baseline and native/managed incremental builds passed with zero warnings or errors. The WSL baseline used explicit Git revision metadata for the Windows-created worktree.
  • Controlled managed fast-peer reproduction: both TLS 1.2/1.3 cases timed out before the fix and passed afterward. The temporary BIO scheduling hook was removed before final validation.
  • Full System.Net.Security functional suite: 5,127 passed, 0 failed, 8 existing conditional skips.
  • Focused four-case theory repeated five times in each reported configuration (DOTNET_JitStress=2 with tiering enabled, and with DOTNET_JitStressRegs=4 and tiering disabled): 40 passed, 0 skipped.
  • Native schedule/certificate controls: 2,400 cases, zero unexpected outcomes.

Validation used Ubuntu WSL and OpenSSL 3.5.3, not the exact AzureLinux CI image. Older OpenSSL versions and forced write-backpressure were not exercised.

Resolves #134222

Note

This pull request was authored with assistance from GitHub Copilot.

Keep the first fd-mode handshake call limited to sending the client-certificate request so a fast peer cannot complete authentication before the driver starts checking for its response. Cover both ready and idle peers for TLS 1.2 and TLS 1.3.

Co-authored-by: Copilot App <[email protected]>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

@rzikm
rzikm requested a review from a team October 27, 2026 17:02
@rzikm
rzikm merged commit 5233491 into dotnet:main Oct 28, 2026
104 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

System.TimeoutException in System.Net.Security.Tests.TlsSessionTests.SocketBoundSession_RequestClientCertificate_DrivesSecondHandshakeToCompletion

2 participants