diff --git a/src/server.c b/src/server.c index 31418e01b..c0e59c86c 100644 --- a/src/server.c +++ b/src/server.c @@ -1910,6 +1910,13 @@ int serverCron(struct aeEventLoop *eventLoop, long long id, void *clientData) { if (WIFSIGNALED(statloc)) bysignal = WTERMSIG(statloc); + /* sigKillChildHandler catches the signal and calls exit(), but we + * must make sure not to flag lastbgsave_status, etc incorrectly. */ + if (exitcode == SIGUSR1) { + bysignal = SIGUSR1; + exitcode = 1; + } + if (pid == -1) { serverLog(LL_WARNING,"wait3() returned an error: %s. " "rdb_child_pid = %d, aof_child_pid = %d, module_child_pid = %d", @@ -4578,7 +4585,7 @@ static void sigKillChildHandler(int sig) { UNUSED(sig); /* this handler is needed to resolve a valgrind warning */ serverLogFromHandler(LL_WARNING, "Received SIGUSR1 in child, exiting now."); - exitFromChild(1); + exitFromChild(SIGUSR1); } void setupChildSignalHandlers(void) { diff --git a/tests/integration/rdb.tcl b/tests/integration/rdb.tcl index 58a098edc..b364291ee 100644 --- a/tests/integration/rdb.tcl +++ b/tests/integration/rdb.tcl @@ -115,3 +115,17 @@ start_server_and_kill_it [list "dir" $server_path] { } } } + +start_server {} { + test {Test FLUSHALL aborts bgsave} { + r config set rdb-key-save-delay 1000 + r debug populate 1000 + r bgsave + assert_equal [s rdb_bgsave_in_progress] 1 + r flushall + after 200 + assert_equal [s rdb_bgsave_in_progress] 0 + # make sure the server is still writable + r set x xx + } +} \ No newline at end of file