From 1cbced6c6f1034e265dc0e12ad49bdab89448cdd Mon Sep 17 00:00:00 2001 From: Joseph Birr-Pixton Date: Wed, 10 Apr 2024 15:26:38 +0100 Subject: [PATCH] Quieten `WouldBlock` errors These should not be put on the openssl error stack, and should not be logged either. --- rustls-libssl/src/error.rs | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/rustls-libssl/src/error.rs b/rustls-libssl/src/error.rs index d444296..43fd857 100644 --- a/rustls-libssl/src/error.rs +++ b/rustls-libssl/src/error.rs @@ -26,6 +26,7 @@ enum Reason { UnableToGetWriteLock, OperationFailed, Unsupported, + WouldBlock, Alert(AlertDescription), } @@ -39,6 +40,7 @@ impl From for c_int { UnableToGetWriteLock => (ERR_RFLAG_FATAL as i32) | ERR_RFLAG_COMMON | 272, OperationFailed => (ERR_RFLAG_FATAL as i32) | ERR_RFLAG_COMMON | 263, Unsupported => ERR_RFLAG_COMMON | 268, + WouldBlock => 0, // `sslerr.h` Alert(alert) => 1000 + u8::from(alert) as c_int, } @@ -109,15 +111,26 @@ impl Error { } pub fn from_io(err: std::io::Error) -> Self { - Self { - lib: Lib::User, - reason: Reason::OperationFailed, - string: Some(err.to_string()), + match err.kind() { + std::io::ErrorKind::WouldBlock => Self { + lib: Lib::User, + reason: Reason::WouldBlock, + string: None, + }, + _ => Self { + lib: Lib::User, + reason: Reason::OperationFailed, + string: Some(err.to_string()), + }, } } /// Add this error to the openssl error stack. pub fn raise(self) -> Self { + if !self.quiet() { + return self; + } + log::error!("raising {self:?}"); let cstr = CString::new( self.string @@ -140,6 +153,13 @@ impl Error { } self } + + /// `WouldBlock` errors never make it on the error stack. + /// + /// They are usual in the use of non-blocking BIOs. + fn quiet(&self) -> bool { + matches!(self.reason, Reason::WouldBlock) + } } // These conversions determine how errors are reported from entry point