Skip to content

Commit

Permalink
Fix checking for server-side closure of HTTPS connections
Browse files Browse the repository at this point in the history
When an SSL connection times out due to being closed by server, a
different error code is returned, so we need to check for it too in
was_closed_by_server().

Without this, losing connection was not detected at all when using
HTTPS, resulting in "Failed to read HTTP status line" errors whenever
the same http_client was reused after more than the server keep alive
timeout of inactivity.

See microsoft#592.
  • Loading branch information
vadz committed May 8, 2018
1 parent d87fa2b commit fb08ce5
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions Release/src/http/client/http_client_asio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#endif
#include <boost/asio.hpp>
#include <boost/asio/ssl.hpp>
#include <boost/asio/ssl/error.hpp>
#include <boost/asio/steady_timer.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/bind.hpp>
Expand Down Expand Up @@ -191,6 +192,21 @@ class asio_connection
return true;
}

if (is_ssl())
{
// For SSL connections, we can also get a different error due to
// incorrect secure connection shutdown if it was closed by the
// server due to inactivity. Unfortunately, the exact error we get
// in this case depends on the Boost.Asio version used.
#if BOOST_ASIO_VERSION >= 101008
if (boost::asio::ssl::error::stream_truncated == ec)
return true;
#else // Asio < 1.10.8 didn't have ssl::error::stream_truncated
if (boost::system::error_code(ERR_PACK(ERR_LIB_SSL, 0, SSL_R_SHORT_READ), boost::asio::error::get_ssl_category()) == ec)
return true;
#endif
}

return false;
}

Expand Down

0 comments on commit fb08ce5

Please sign in to comment.