Skip to content

Commit 2d289cc

Browse files
committed
Unless there's a server shutdown, keep accepting connections on error
Previously, it was possible for wthttp to stop accepting new connections if an error occurred during accept (e.g. by exceeding the open file limit) We should always try to accept again, unless the operation is aborted due to server shutdown.
1 parent f79eaea commit 2d289cc

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

src/http/Server.C

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -609,27 +609,40 @@ void Server::handleTcpAccept(TcpListener *listener, const Wt::AsioWrapper::error
609609
if (!e) {
610610
connection_manager_.start(listener->new_connection);
611611
listener->new_connection.reset(new TcpConnection(wt_.ioService(), this,
612-
connection_manager_, request_handler_));
613-
listener->acceptor.async_accept(listener->new_connection->socket(),
614-
accept_strand_.wrap(
615-
std::bind(&Server::handleTcpAccept, this,
616-
listener, std::placeholders::_1)));
612+
connection_manager_, request_handler_));
613+
} else if (!listener->acceptor.is_open()) {
614+
// server shutdown
615+
LOG_DEBUG("handleTcpAccept: async_accept error (acceptor closed, probably server shutdown): " << e.message());
616+
return;
617+
} else {
618+
LOG_ERROR("handleTcpAccept: async_accept error: " << e.message());
617619
}
620+
621+
listener->acceptor.async_accept(listener->new_connection->socket(),
622+
accept_strand_.wrap(
623+
std::bind(&Server::handleTcpAccept, this,
624+
listener, std::placeholders::_1)));
618625
}
619626

620627
#ifdef HTTP_WITH_SSL
621628
void Server::handleSslAccept(SslListener *listener, const Wt::AsioWrapper::error_code& e)
622629
{
623-
if (!e)
624-
{
630+
if (!e) {
625631
connection_manager_.start(listener->new_connection);
626632
listener->new_connection.reset(new SslConnection(wt_.ioService(), this,
627-
ssl_context_, connection_manager_, request_handler_));
628-
listener->acceptor.async_accept(listener->new_connection->socket(),
629-
accept_strand_.wrap(
630-
std::bind(&Server::handleSslAccept, this,
631-
listener, std::placeholders::_1)));
633+
ssl_context_, connection_manager_, request_handler_));
634+
} else if (!listener->acceptor.is_open()) {
635+
// server shutdown
636+
LOG_DEBUG("handleSslAccept: async_accept error (acceptor closed, probably server shutdown): " << e.message());
637+
return;
638+
} else {
639+
LOG_ERROR("handleSslAccept: async_accept error: " << e.message());
632640
}
641+
642+
listener->acceptor.async_accept(listener->new_connection->socket(),
643+
accept_strand_.wrap(
644+
std::bind(&Server::handleSslAccept, this,
645+
listener, std::placeholders::_1)));
633646
}
634647
#endif // HTTP_WITH_SSL
635648

0 commit comments

Comments
 (0)