Skip to content

Commit 3eec5eb

Browse files
author
David Übler
committed
build TlsConnector in blocking threadpool
The openssl TlsConnector synchronously loads certificates from files. Loading these files can block for tens of milliseconds.
1 parent c52e129 commit 3eec5eb

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

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

Lines changed: 4 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,9 @@ pub async fn handshake<S: Socket>(
6162
builder.identity(identity);
6263
}
6364

64-
let connector = builder.build().map_err(Error::tls)?;
65+
let connector = rt::spawn_blocking(move || builder.build())
66+
.await
67+
.map_err(Error::tls)?;
6568

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

0 commit comments

Comments
 (0)