From ccaef5c923a14dc183c50530f52ada0fda012179 Mon Sep 17 00:00:00 2001 From: Oran Agra Date: Wed, 9 Nov 2022 10:02:18 +0200 Subject: diskless master, avoid bgsave child hung when fork parent crashes (#11463) During a diskless sync, if the master main process crashes, the child would have hung in `write`. This fix closes the read fd on the child side, so that if the parent crashes, the child will get a write error and exit. This change also fixes disk-based replication, BGSAVE and AOFRW. In that case the child wouldn't have been hang, it would have just kept running until done which may be pointless. There is a certain degree of risk here. in case there's a BGSAVE child that could maybe succeed and the parent dies for some reason, the old code would have let the child keep running and maybe succeed and avoid data loss. On the other hand, if the parent is restarted, it would have loaded an old rdb file (or none), and then the child could reach the end and rename the rdb file (data conflicting with what the parent has), or also have a race with another BGSAVE child that the new parent started. Note that i removed a comment saying a write error will be ignored in the child and handled by the parent (this comment was very old and i don't think relevant). --- tests/support/util.tcl | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'tests/support') diff --git a/tests/support/util.tcl b/tests/support/util.tcl index 51a8420a3..a7332d29c 100644 --- a/tests/support/util.tcl +++ b/tests/support/util.tcl @@ -627,6 +627,14 @@ proc get_child_pid {idx} { return $child_pid } +proc process_is_alive pid { + if {[catch {exec ps -p $pid} err]} { + return 0 + } else { + return 1 + } +} + proc cmdrstat {cmd r} { if {[regexp "\r\ncmdstat_$cmd:(.*?)\r\n" [$r info commandstats] _ value]} { set _ $value -- cgit v1.2.1