Skip to content

Commit 064d649

Browse files
davidueblerDavid Üblerabonander
authored
native tls handshake: build TlsConnector in blocking threadpool (#4027)
* build TlsConnector in blocking threadpool The openssl TlsConnector synchronously loads certificates from files. Loading these files can block for tens of milliseconds. * Update sqlx-core/src/net/tls/tls_native_tls.rs --------- Co-authored-by: David Übler <[email protected]> Co-authored-by: Austin Bonander <[email protected]>
1 parent c52e129 commit 064d649

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

sqlx-core/src/net/tls/tls_native_tls.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::io::ReadBuf;
44
use crate::net::tls::util::StdSocket;
55
use crate::net::tls::TlsConfig;
66
use crate::net::Socket;
7+
use crate::rt;
78
use crate::Error;
89

910
use native_tls::{HandshakeError, Identity};
@@ -61,7 +62,11 @@ pub async fn handshake<S: Socket>(
6162
builder.identity(identity);
6263
}
6364

64-
let connector = builder.build().map_err(Error::tls)?;
65+
// The openssl TlsConnector synchronously loads certificates from files.
66+
// Loading these files can block for tens of milliseconds.
67+
let connector = rt::spawn_blocking(move || builder.build())
68+
.await
69+
.map_err(Error::tls)?;
6570

6671
let mut mid_handshake = match connector.connect(config.hostname, StdSocket::new(socket)) {
6772
Ok(tls_stream) => return Ok(NativeTlsSocket { stream: tls_stream }),

0 commit comments

Comments
 (0)