Repository navigation
tls: the proactor frees the TLS services started on it when it stops (#46) - #57
Merged
Merged
Conversation
…46) Nothing freed what TlsService.start built: the SSL_CTX with its certificate and key, the ALPN list its callback reads and the kTLS handoff's buffer. A host starting servers again in one process kept them all, once per proactor per start. Hosts already stop their proactors, and teardown, on the proactor's own thread, already frees all else the proactor owns. So start hands each service to its proactor, and teardown frees them last. A context of 0 marks a freed service, which accept refuses, and a start whose context fails to build frees the ALPN list it made.
MDA2AV
force-pushed
the
fix/tls-service-close
branch
from
November 11, 2026 17:02
8bd0946 to
034c503
Compare
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #46.
Nothing freed what
TlsService.startbuilt: theSSL_CTXwith its certificate and key, the ALPN list its callback reads, and the kTLS handoff's buffer, made on first use. A host starting servers again in one process kept them all, once per proactor per start.The proactor now frees them when it stops, as MDA2AV/ioxide#562 has the reactor do, so hosts change nothing.
starthands each service to its proactor, andteardown, on the proactor's own thread, frees them last, after the drain #53 added. A session still open holds its own reference, so the context goes with the last of them. A context of 0 marks a freed service, so there is no new flag, andacceptrefuses it. A start whose context fails to build now frees the ALPN list it made. The Ktor engine gets this with no change.With #54, now merged. Every proactor started with one
TlsOptionsinstance shares one context, so the first to stop must not free it under the rest.TlsOptionsalso keeps the ALPN list and a count of the services on the context, under the lock #54 builds it under:startraises the count. A proactor started while others still run shares the context.freedrops its own handoff buffer and lowers the count. The one that reaches zero frees the context and the list and clears them, so a start after that builds another.Tests.
TlsResumptionTest: one-proactor servers on one port, as a server's proactors are. With one of them left, it is the one that answers:With the context freed at the first stop instead, the test binary crashes (SIGSEGV). With a count that never reaches zero, the last check fails.
TlsServiceTeardownTest: a server of two proactors sharing one options instance, started and stopped a hundred times, leaves the native heap where it was, measured withmallinfo: 0 KiB of growth. Withteardownnot freeing, it fails at 408 KiB.Native: all 337 passed. JVM: all 109 passed, on main with proactor, tcp, tls: a stop ends what waits on the proactor, so a parked handler unwinds, and a call from another thread after it returns instead of waiting forever (#29) #53 to tls: kTLS reads each traffic secret where BoringSSL wrote its key-log line, and the JVM's HMAC leaves no copy of it (#45) #56 merged.