fix: Fix bugs in new webserver (#1780)

Fixes #919.

Fixes bugs for new webserver:
- Unhandled exception when closing already closed websocket
- No pings for plain websocket connection
- Server drops websocket connection when client responds to pings but
doesn't send anything

Also changing API of ng connections. Now timeout is set by a separate
method instead of providing it for each call.
This commit is contained in:
Sergey Kuznetsov
2024-12-19 15:14:04 +00:00
committed by GitHub
parent c4b87d2a0a
commit 7d4e3619b0
13 changed files with 238 additions and 204 deletions

View File

@@ -223,6 +223,7 @@ Server::onWs(MessageHandler handler)
std::optional<std::string>
Server::run()
{
LOG(log_.info()) << "Starting ng::Server";
auto acceptor = makeAcceptor(ctx_.get(), endpoint_);
if (not acceptor.has_value())
return std::move(acceptor).error();
@@ -236,6 +237,7 @@ Server::run()
boost::asio::ip::tcp::socket socket{ctx_.get().get_executor()};
acceptor.async_accept(socket, yield[errorCode]);
LOG(log_.trace()) << "Accepted a new connection";
if (errorCode) {
LOG(log_.debug()) << "Error accepting a connection: " << errorCode.what();
continue;
@@ -290,6 +292,7 @@ Server::handleConnection(boost::asio::ip::tcp::socket socket, boost::asio::yield
}
return;
}
LOG(log_.trace()) << connectionExpected.value()->tag() << "Connection created";
boost::asio::spawn(
ctx_.get(),