From 9fa0bcc67d79d90996cd4ec2b5af56d051ef6be7 Mon Sep 17 00:00:00 2001 From: Ilya Dryomov Date: Mon, 9 Dec 2024 11:19:57 +0100 Subject: [PATCH] librbd/migration/HttpClient: ignore stream_truncated when shutting down SSL Propagate ec to handle_disconnect() and use it to suppress stream_truncated errors. Here is a quote from Beast documentation [1]: // Gracefully shutdown the SSL/TLS connection error_code ec; stream.shutdown(ec); // Non-compliant servers don't participate in the SSL/TLS shutdown process and // close the underlying transport layer. This causes the shutdown operation to // complete with a `stream_truncated` error. One might decide not to log such // errors as there are many non-compliant servers in the wild. if(ec != net::ssl::error::stream_truncated) log(ec); ... and a commit that made ignoring stream_truncated safe [2]: // ssl::error::stream_truncated, also known as an SSL "short read", // indicates the peer closed the connection without performing the // required closing handshake // [...] // When a short read would cut off the end of an HTTP message, // Beast returns the error beast::http::error::partial_message. // Therefore, if we see a short read here, it has occurred // after the message has been completed, so it is safe to ignore it. [1] https://www.boost.org/doc/libs/develop/libs/beast/doc/html/beast/using_io/ssl_tls_shutdown.html [2] https://github.com/boostorg/beast/commit/094f5ec5cb3be1c3ce2d985564f1f39e9bed74ff Signed-off-by: Ilya Dryomov --- src/librbd/migration/HttpClient.cc | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/librbd/migration/HttpClient.cc b/src/librbd/migration/HttpClient.cc index 769187586e434..86a4adf4c597a 100644 --- a/src/librbd/migration/HttpClient.cc +++ b/src/librbd/migration/HttpClient.cc @@ -664,8 +664,9 @@ protected: ldout(cct, 15) << dendl; m_stream.async_shutdown( - asio::util::get_callback_adapter([this, on_finish](int r) { - shutdown(r, on_finish); })); + [this, on_finish](boost::system::error_code ec) { + handle_disconnect(ec, on_finish); + }); } void reset_stream() override { @@ -759,12 +760,18 @@ private: on_finish->complete(0); } - void shutdown(int r, Context* on_finish) { + void handle_disconnect(boost::system::error_code ec, Context* on_finish) { auto http_client = this->m_http_client; auto cct = http_client->m_cct; - ldout(cct, 15) << "r=" << r << dendl; + ldout(cct, 15) << "ec=" << ec.what() << dendl; - on_finish->complete(r); + if (ec && ec != boost::asio::ssl::error::stream_truncated) { + lderr(cct) << "failed to shut down SSL: " << ec.message() << dendl; + on_finish->complete(-ec.value()); + return; + } + + on_finish->complete(0); } }; -- 2.39.5