Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions include/mp/proxy-io.h
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,12 @@ void _Listen(const std::shared_ptr<Listener>& listener, EventLoop& loop, InitImp
if (resume_accept) _Listen<InitInterface>(listener, loop, init);
});
_Listen<InitInterface>(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<InitInterface>(listener, loop, init);
}));
}

Expand Down
15 changes: 15 additions & 0 deletions test/mp/test/listen_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In commit "Keep listening after a failed accept in ListenConnections" (38391eb)

Can this be checked with KJ_SYSCALL?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In commit "Keep listening after a failed accept in ListenConnections" (d8e5395)

Would be good to add a comment here that this close is a little racy, if the socket not closed before accepted the test could appear to crash when there is still a problem.


// The server should still accept and serve later clients.
auto client = std::make_unique<ClientSetup>(server.listener.MakeConnectedSocket());
server.WaitForConnectedCount(1);
KJ_EXPECT(client->client->add(1, 2) == 3);
}

} // namespace
} // namespace test
} // namespace mp
Loading