]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd/migration/HttpClient: ignore stream_truncated when shutting down SSL
authorIlya Dryomov <idryomov@gmail.com>
Mon, 9 Dec 2024 10:19:57 +0000 (11:19 +0100)
committerIlya Dryomov <idryomov@gmail.com>
Fri, 13 Dec 2024 12:44:45 +0000 (13:44 +0100)
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 <idryomov@gmail.com>
src/librbd/migration/HttpClient.cc

index 769187586e4347ebb9c954efdee29a7622ad3dfa..86a4adf4c597abf6814115314ffae3d5e5c8aa8c 100644 (file)
@@ -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);
   }
 };