Experimental: Recycle SslStreamCertificateContext objects for client and server #629
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.
Are you a customer of Octopus Deploy? Please contact our support team so we can triage your PR, so that we can make sure it's handled appropriately.
Background
dotnet/runtime#110803 (comment)
Results
When running Halibut on .NET 9, we appear to be affected by the memory leak detailed in dotnet/runtime#110803. This says it will be fixed in .NET 10, but there is significant time until that is available.
I experimented with
DOTNET_SYSTEM_NET_SECURITY_DISABLETLSRESUME=1
as a workaround, and while it helps reduce the rate of memory leaking, it does not solve it.This PR implements the second proposed solution, which is to refactor our code to share an
SslStreamCertificateContext
across connections.Note: We do not handle the
SslStreamCertificateContext
object directly, but rather take the second path and recycle theSslServerAuthenticationOptions
object which owns the certificate context.Also
While the github issue only describes a memory leak when dealing with a server-side stream,
SslStreamCertificateContext
is also employed on the client side since it was added intoSslClientAuthenticationOptions
in dotnet 8If the certificate context leaks an OpenSSL handle when used for server auth, it seems reasonable that it could also leak when used for client auth. So this PR also reuses
SslClientAuthenticationOptions
by way of a cache, to see if that helps.How to review this PR
Quality ✔️
Pre-requisites