Skip to content

Commit 2fe831b

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 2fe831b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

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

Lines changed: 2 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,7 @@ 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()).await.map_err(Error::tls)?;
6566

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

0 commit comments

Comments
 (0)