From 0986964babc07eb1180b39f8a6c1d37530486564 Mon Sep 17 00:00:00 2001 From: Uri Yagelnik Date: Tue, 9 Jul 2024 12:43:15 +0000 Subject: [PATCH] Do not send pending writes to I/O threads while OOM Signed-off-by: Uri Yagelnik --- src/networking.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/networking.c b/src/networking.c index b249aa61f3..039835bc09 100644 --- a/src/networking.c +++ b/src/networking.c @@ -2397,6 +2397,8 @@ int handleClientsWithPendingWrites(void) { listIter li; listNode *ln; listRewind(server.clients_pending_write, &li); + /* Avoid sending to I/O threads during out-of-memory conditions to free clients' COBs as quickly as possible */ + int try_send_to_io_threads = server.active_io_threads_num > 1 && getMaxmemoryState(NULL, NULL, NULL, NULL) == C_OK; while ((ln = listNext(&li))) { client *c = listNodeValue(ln); c->flag.pending_write = 0; @@ -2412,7 +2414,7 @@ int handleClientsWithPendingWrites(void) { if (!clientHasPendingReplies(c)) continue; /* If we can send the client to the I/O thread, let it handle the write. */ - if (trySendWriteToIOThreads(c) == C_OK) continue; + if (try_send_to_io_threads && trySendWriteToIOThreads(c) == C_OK) continue; /* We can't write to the client while IO operation is in progress. */ if (c->io_write_state != CLIENT_IDLE || c->io_read_state != CLIENT_IDLE) continue;