From d8e5395ed8e6f21fc847b65148c2ec3c34bce524 Mon Sep 17 00:00:00 2001 From: xyzconstant <263061129+xyzconstant@users.noreply.github.com> Date: Thu, 16 Jul 2026 21:24:43 -0300 Subject: [PATCH] Keep listening after a failed accept in `ListenConnections` A failed `accept()` would stop the server from accepting any further connections, because the accept loop was only continued after a successful accept. Handle this by also keeping the accept loop running on failures. --- include/mp/proxy-io.h | 6 ++++++ test/mp/test/listen_tests.cpp | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/mp/proxy-io.h b/include/mp/proxy-io.h index c2a8d433..14edcf7c 100644 --- a/include/mp/proxy-io.h +++ b/include/mp/proxy-io.h @@ -905,6 +905,12 @@ void _Listen(const std::shared_ptr& listener, EventLoop& loop, InitImp if (resume_accept) _Listen(listener, loop, init); }); _Listen(listener, loop, init); + }, + // Keep listening if a single accept() fails, so the server does not + // stop accepting future connections. + [&loop, &init, listener](const kj::Exception& e) { + MP_LOG(loop, Log::Warning) << "IPC server: accept failed:" << kj::str(e).cStr(); + _Listen(listener, loop, init); })); } diff --git a/test/mp/test/listen_tests.cpp b/test/mp/test/listen_tests.cpp index 1506eaa4..54b4bd27 100644 --- a/test/mp/test/listen_tests.cpp +++ b/test/mp/test/listen_tests.cpp @@ -289,6 +289,21 @@ KJ_TEST("ListenConnections accepts multiple connections") KJ_EXPECT(client3->client->add(3, 4) == 7); } +KJ_TEST("ListenConnections survives a client that disconnects before being accepted") +{ + ListenSetup server; + + // Connect and close before the server has a chance to accept() the + // connection. + int fd = server.listener.MakeConnectedSocket(); + close(fd); + + // The server should still accept and serve later clients. + auto client = std::make_unique(server.listener.MakeConnectedSocket()); + server.WaitForConnectedCount(1); + KJ_EXPECT(client->client->add(1, 2) == 3); +} + } // namespace } // namespace test } // namespace mp