diff --git a/boring/src/ssl/mod.rs b/boring/src/ssl/mod.rs index c382375d..61829281 100644 --- a/boring/src/ssl/mod.rs +++ b/boring/src/ssl/mod.rs @@ -3054,7 +3054,24 @@ impl SslStream { 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) + } } }