Skip to content

Commit

Permalink
Don't return shutdown errors during shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
nox committed Dec 6, 2022
1 parent 3efaf63 commit 1d3fb25
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion boring/src/ssl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3054,7 +3054,24 @@ impl<S: Read + Write> SslStream<S> {
match unsafe { ffi::SSL_shutdown(self.ssl.as_ptr()) } {
0 => Ok(ShutdownResult::Sent),
1 => Ok(ShutdownResult::Received),
n => Err(self.make_error(n)),
n => {
let e = self.make_error(n);

// If boring returns PROTOCOL_IS_SHUTDOWN then the connection
// has already been shutdown and we can just return Ok(()), as
// this was exactly what we wanted to do anyway.
if e.code() == ErrorCode::SSL {
if let Some(stack) = e.ssl_error() {
if let Some(first) = stack.errors().first() {
if first.code() as i32 == boring_sys::SSL_R_PROTOCOL_IS_SHUTDOWN {
return Ok(ShutdownResult::Received);
}
}
}
}

Err(e)
}
}
}

Expand Down

0 comments on commit 1d3fb25

Please sign in to comment.