Skip to content

Conversation

goffrie
Copy link
Contributor

@goffrie goffrie commented Mar 2, 2025

Constructing a TlsConnector is fairly expensive - it can involve searching for and parsing certificates, for example.
Both native-tls and rustls therefore allow a single TlsConnector to be used to connect many times.

To avoid adding a fallible (and async) initialization step and therefore preserve the public API of this crate, this PR caches the TlsConnector beside the SslOpts using a tokio OnceCell, so that any error from its construction still gets emitted at the same point.

The SslOpts and corresponding TlsConnector are stored together in a struct in order to avoid accidentally mutating the SslOpts without clearing the connector.

I've also slightly refactored the no-TLS case to behave more uniformly with the rustls and native-tls implementations.

@blackbeam blackbeam merged commit 2e8a2b3 into blackbeam:master Mar 17, 2025
20 checks passed
@goffrie goffrie deleted the shared-connector branch April 10, 2025 21:39
@harsh-98
Copy link

We are still calling clone on the TlsConnector that we get from native tls or rustls. https://github.com/blackbeam/mysql_async/blob/master/src/opts/mod.rs#L1179.

@goffrie
Copy link
Contributor Author

goffrie commented Apr 25, 2025

Correct. In all implementations (rustls, openssl, securityframework, schannel), the underlying configuration object is reference counted and cheaply cloneable.

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.

3 participants