feat: Graceful shutdown (#1801)

Fixes #442.
This commit is contained in:
Sergey Kuznetsov
2025-01-22 13:09:16 +00:00
committed by GitHub
parent 12e6fcc97e
commit 957028699b
41 changed files with 1073 additions and 191 deletions

View File

@@ -77,6 +77,7 @@ class HttpConnection : public UpgradableConnection {
StreamType stream_;
std::optional<boost::beast::http::request<boost::beast::http::string_body>> request_;
std::chrono::steady_clock::duration timeout_{kDEFAULT_TIMEOUT};
bool closed_{false};
public:
HttpConnection(
@@ -152,6 +153,13 @@ public:
void
close(boost::asio::yield_context yield) override
{
// This is needed because calling async_shutdown() multiple times may lead to hanging coroutines.
// See WsConnection for more details.
if (closed_)
return;
closed_ = true;
[[maybe_unused]] boost::system::error_code error;
if constexpr (IsSslTcpStream<StreamType>) {
boost::beast::get_lowest_layer(stream_).expires_after(timeout_);