From a7061d8f8e43388ef3ca584b04acb9b4c2fc7148 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Thu, 14 May 2020 22:52:34 +0300 Subject: [PATCH] dict: Fix deinitializing dict iteration if client disconnects If the client's ostream was full at the disconnection time, the iteration wasn't aborted. Instead, the connection was kept forever and its input callback was kept being called rapidly, causing 100% CPU usage. --- src/dict/dict-commands.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/dict/dict-commands.c b/src/dict/dict-commands.c index 85d57e9ddf..003a15e575 100644 --- a/src/dict/dict-commands.c +++ b/src/dict/dict-commands.c @@ -264,13 +264,17 @@ cmd_iterate_flush_finish(struct dict_connection_cmd *cmd, string_t *str) static int cmd_iterate_flush(struct dict_connection_cmd *cmd) { - string_t *str; + string_t *str = t_str_new(256); const char *key, *value; + if (cmd->conn->destroyed) { + cmd_iterate_flush_finish(cmd, str); + return 1; + } + if (!dict_connection_flush_if_full(cmd->conn)) return 0; - str = t_str_new(256); while (dict_iterate(cmd->iter, &key, &value)) { cmd->rows++; str_truncate(str, 0); -- 2.47.3