Skip to content

tls: every proactor started with one TlsOptions shares its context, so a session ticket resumes on any of them (#38) - #54

Merged
MDA2AV merged 2 commits into
mainfrom
fix/shared-tls-contexts
Nov 11, 2026
Merged

MDA2AV merged 2 commits into
mainfrom
fix/shared-tls-contexts

Conversation

@MDA2AV

@MDA2AV MDA2AV commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Closes #38.

Each TlsService built its own SSL_CTX, and so its own ticket keys, while SO_REUSEPORT picks the proactor by hashing the connection. A returning client resumed about one time in N, and a miss is a full handshake on the proactor thread.

This follows MDA2AV/ioxide#559: the context belongs to the server, not the proactor.

  • Every proactor started with the same TlsOptions instance shares one context, built by the first to start, under a lock taken only at startup. The rest take it.
  • BoringSSL keeps rotating the ticket keys itself.
  • The ALPN wire is built once, with the context. Nothing else on it is per proactor: its callbacks are static, and ALPN reads immutable bytes.
  • A proactor started with an options instance of its own still builds its own context, as before.
  • TlsOptions now says to hand the same instance to every proactor.

Where kron differs.

  • ioxide keeps the shared contexts in a ConditionalWeakTable keyed by the options. Common Kotlin has no weak table, so here the context is an internal field on the TlsOptions instance. TlsOptions is a plain class, so identity is what shares, as in ioxide.
  • kron has no certificate rotation, so there's nothing to share there.

Test. TlsResumptionTest (native): 4 proactors on one port, and a TLS 1.2 client returning 20 times with the last session it got. Every return must resume; on main, 5 of 20 did.

  • It's TLS 1.2 because a session is resumable there as soon as its handshake is done. TLS 1.3 resumes from the same context ticket keys.
  • It also checks that the returns reached more than one proactor, so it can't pass on one.
  • TlsTestClient gained a session to offer, resumed and session().

With the change.

  • Native: all 319 passed, the 318 from before plus this one.
  • JVM: all 93 passed.
  • kTLS: the kTLS tests print "skipped" locally, since this machine has no tls module.

@MDA2AV
MDA2AV merged commit 92e7b3d into main Nov 11, 2026
3 checks passed
MDA2AV added a commit that referenced this pull request Nov 11, 2026
…ptions (#54) count their services, so the last to stop frees the context

With #54 every proactor started with one TlsOptions instance shares its context, so the first proactor to stop could no longer free it under the rest. TlsOptions also keeps the ALPN list the context's callback reads and a count of the services on it, under the lock #54 builds it under: start raises the count, free lowers it, and the one that reaches zero frees the context and the list and clears them, so a start after that builds another. Each service still frees its own kTLS handoff buffer, and teardown frees the services after #53's drain, last of all.

Tests: TlsResumptionTest runs one-proactor servers on one port through a stop, a later start, and a start after the last stopped; the heap test runs two proactors sharing one options instance.
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.

tls: a ticket resumes only on the proactor that issued it, so resumption falls to about 1/N

1 participant