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>
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 {
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);
}
};