Skip to content

[release/11.0] Fix TlsSessionTests TLS resume flakiness by using a unique SNI - #134369

Merged
ViveliDuCh merged 1 commit into
release/11.0from
backport/pr-132749-to-release/11.0
Sep 22, 2026
Merged

ViveliDuCh merged 1 commit into
release/11.0from
backport/pr-132749-to-release/11.0

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Backport of #132749 to release/11.0

/cc @ViveliDuCh @rzikm

Customer Impact

  • Customer reported
  • Found internally

[Select one or both of the boxes. Describe how this issue impacts customers, citing the expected and actual behaviors and scope of the issue. If customer-reported, provide the issue number.]

Regression

  • Yes
  • No

[If yes, specify when the regression was introduced. Provide the PR or commit if known.]

Testing

[How was the fix verified? How was the issue missed previously? What tests were added?]

Risk

[High/Medium/Low. Justify the indication by mentioning how risks were measured and addressed.]

IMPORTANT: If this backport is for a servicing release, please verify that:

  • For .NET 8 and .NET 9: The PR target branch is release/X.0-staging, not release/X.0.
  • For .NET 10+: The PR target branch is release/X.0 (no -staging suffix).

Package authoring no longer needed in .NET 9

IMPORTANT: Starting with .NET 9, you no longer need to edit a NuGet package's csproj to enable building and bump the version.
Keep in mind that we still need package authoring in .NET 8 and older versions.

Fixes #132111

### Root cause

This is a test isolation bug, not a product bug.

`ServerSession_TlsResume_HonorsAllowTlsResumeOption` used the server
certificate's name as the client `TargetHost`. On Linux the client-side
OpenSSL session cache lives on a **process-wide `SSL_CTX`**, keyed only
by `(isClient, protocols, client certificate)`
([`Interop.OpenSsl.cs`](https://github.com/dotnet/runtime/blob/main/src/libraries/Common/src/Interop/Unix/System.Security.Cryptography.Native/Interop.OpenSsl.cs)),
and that context holds a **single session per SNI name**
(`SafeSslContextHandle._sslSessions`).

Test classes in this assembly run in parallel, and ~85 call sites use a
non-unique `TargetHost`. So a concurrently running test could overwrite
this test's cached ticket with one issued by *its own* server. The
second handshake then offered a ticket that this test's server could not
decrypt, so it fell back to a full handshake — and the ClientHello was
*larger* than the first one because of the `pre_shared_key` extension,
which is why the reported failure shows the second handshake exceeding
the first.

### Verification

I reproduced the failure deterministically with a temporary test that
poisons the cache in exactly that way (a client with the same protocols
and no client certificate connecting to a *different* server under the
same SNI, in between the two measured handshakes). It reproduced the CI
failure byte-for-byte:

```
Expected resumed handshake to be smaller. first=5513 second=5816
```

which is identical to the numbers reported in #132111. The temporary
repro is not part of this change.

### Fix

Use a unique SNI name per run, matching the existing precedent in
`SslStreamTlsResumeTests`, which already does this for the same reason.

### Testing

On Linux x64:

- Baseline `./build.sh clr+libs -rc release` — succeeded
- `ServerSession_TlsResume_HonorsAllowTlsResumeOption`, all 4 cases —
pass
- Full `System.Net.Security.Tests` (5041 tests) — clean

> [!NOTE]
> This pull request description was generated with the assistance of
GitHub Copilot.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@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: @karelz, @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

@mrek-msft

Copy link
Copy Markdown
Member

Test only change. Adding servicing-approved.

@mrek-msft mrek-msft added the Servicing-approved Approved for servicing release label Sep 21, 2026
@ViveliDuCh

Copy link
Copy Markdown
Member

/ba-g unrelated test failures tracked by #134367

@ViveliDuCh
ViveliDuCh merged commit 499b227 into release/11.0 Sep 22, 2026
85 of 87 checks passed
@ViveliDuCh
ViveliDuCh deleted the backport/pr-132749-to-release/11.0 branch September 22, 2026 00:03
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc2 milestone Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Net Servicing-approved Approved for servicing release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants