From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 64BB6469719 for ; Sat, 7 Nov 2020 02:43:55 +0300 (MSK) From: Vladislav Shpilevoy Date: Sat, 7 Nov 2020 00:43:53 +0100 Message-Id: <796ca0ba5fe99ec3c0b8370f1d955dc3c8f23bd2.1604706067.git.v.shpilevoy@tarantool.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 1/1] raft: fix crash in worker fiber List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org, sergepetrenko@tarantool.org Raft worker fiber does all the heavy and yielding jobs. These are 2 - disk write, and network broadcast. Disk write yields. Network broadcast is slow, so it happens at most once per event loop iteration. The worker on each iteration check if any of these 2 jobs is active, and if not, it goes to sleep until an explicit wakeup. But there was a bug. Before going to sleep it did a yield + a check that there is nothing to do. However during the yield new tasks could appear, and the check failed, leading to a crash. The patch reorganizes this part of the code so now the worker does not yield between checking new tasks and going to sleep. No test, because extremely hard to reproduce, and don't want to clog this part of the code with error injections. --- Branch: http://github.com/tarantool/tarantool/tree/gerold103/raft-crash src/box/raft.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/box/raft.c b/src/box/raft.c index e1e60ce94..914b0d68f 100644 --- a/src/box/raft.c +++ b/src/box/raft.c @@ -682,11 +682,11 @@ raft_worker_f(va_list args) raft_worker_handle_broadcast(); is_idle = false; } + if (is_idle) { + assert(raft_is_fully_on_disk()); + fiber_yield(); + } fiber_sleep(0); - if (!is_idle) - continue; - assert(raft_is_fully_on_disk()); - fiber_yield(); } return 0; } -- 2.21.1 (Apple Git-122.3)