Skip to content

Commit

Permalink
Quieten WouldBlock errors
Browse files Browse the repository at this point in the history
These should not be put on the openssl error stack, and should not
be logged either.
  • Loading branch information
ctz committed Apr 10, 2024
1 parent e9b14ae commit 131b25a
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions rustls-libssl/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ enum Reason {
UnableToGetWriteLock,
OperationFailed,
Unsupported,
WouldBlock,
Alert(AlertDescription),
}

Expand All @@ -39,6 +40,7 @@ impl From<Reason> 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,
}
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 131b25a

Please sign in to comment.