Skip to content

Commit

Permalink
ntls: Convert native_tls::WouldBlock to io::Error::TimedOut
Browse files Browse the repository at this point in the history
When the tls handshake starts and the server doesn't respond, the
std::net::TcpStream will return WouldBlock or TimedOut when a
read/write times out to the socket, which in turn native_tls will
convert to a HandshakeError::WouldBlock. Instead of returning back a
io::Error with no type, return io::Error with kind TimedOut.
  • Loading branch information
johan-bjareholt authored and algesten committed Feb 6, 2024
1 parent 825e7ab commit 55c9b19
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/ntls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ impl TlsConnector for native_tls::TlsConnector {
native_tls::HandshakeError::Failure(e) => ErrorKind::ConnectionFailed
.msg("native_tls connect failed")
.src(e),
native_tls::HandshakeError::WouldBlock(_) => {
ErrorKind::Io.msg("Unexpected native_tls::HandshakeError::WouldBlock")
}
native_tls::HandshakeError::WouldBlock(_) => ErrorKind::Io
.msg("native_tls handshake timed out")
.src(std::io::Error::new(
std::io::ErrorKind::TimedOut,
"native_tls handshake timed out",
)),
})?;

Ok(Box::new(stream))
Expand Down

0 comments on commit 55c9b19

Please sign in to comment.