diff mbox series

[pseudo,14/34] pseudo_server: Skip events for clients closed earlier in the batch

Message ID 1794370862-30908-15-git-send-email-mark.hatle@kernel.crashing.org
State New
Headers show
Series Various fixes | expand

Commit Message

Mark Hatle Nov. 11, 2026, 4:20 a.m. UTC
From: Mark Hatle <mark.hatle@amd.com>

The epoll loop handles up to EPOLL_MAX_EVENTS events per wakeup.  If a
client's slot was already closed earlier in the same batch, its event
was treated as an empty read, and close_client() was called again,
decrementing active_clients a second time.  The server starts its idle
shutdown when active_clients reaches 1, so it could exit while clients
were still connected.

Skip events for slots that are no longer in use, as the select() loop
does.

AI-Generated: Uses GitHub Copilot
Signed-off-by: Mark Hatle <mark.hatle@amd.com>
---
 pseudo_server.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/pseudo_server.c b/pseudo_server.c
index b983121..fc5c2c1 100644
--- a/pseudo_server.c
+++ b/pseudo_server.c
@@ -728,7 +728,9 @@  static void pseudo_server_loop_epoll(void)
 							pseudo_debug(PDBGF_SERVER, "Hit max open files.\n");
 						}
 					}
-				} else {
+				} else if (clients[client_id].fd != -1) {
+					/* the client may have been closed earlier in
+					 * this batch of events */
 					int n = 0;
 					ioctl(clients[client_id].fd, FIONREAD, &n);
 					if (n == 0) {