]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fsmonitor: add timeout to daemon stop command
authorPaul Tarjan <github@paulisageek.com>
Thu, 9 Apr 2026 04:59:33 +0000 (04:59 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 9 Apr 2026 17:59:28 +0000 (10:59 -0700)
The "fsmonitor--daemon stop" command polls in a loop waiting for the
daemon to exit after sending a "quit" command over IPC.  If the daemon
fails to shut down (e.g. it is stuck or wedged), this loop spins
forever.

Add a 30-second timeout so the stop command returns an error instead
of blocking indefinitely.

Signed-off-by: Paul Tarjan <github@paulisageek.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fsmonitor--daemon.c

index b2a816dc3fea5ecf38b57a93a9b56dfad2323c3f..53d8ad1f0d2a1735534499d39adc5c705442efad 100644 (file)
@@ -86,6 +86,8 @@ static int do_as_client__send_stop(void)
 {
        struct strbuf answer = STRBUF_INIT;
        int ret;
+       int max_wait_ms = 30000;
+       int elapsed_ms = 0;
 
        ret = fsmonitor_ipc__send_command("quit", &answer);
 
@@ -96,8 +98,16 @@ static int do_as_client__send_stop(void)
                return ret;
 
        trace2_region_enter("fsm_client", "polling-for-daemon-exit", NULL);
-       while (fsmonitor_ipc__get_state() == IPC_STATE__LISTENING)
+       while (fsmonitor_ipc__get_state() == IPC_STATE__LISTENING) {
+               if (elapsed_ms >= max_wait_ms) {
+                       trace2_region_leave("fsm_client",
+                                           "polling-for-daemon-exit", NULL);
+                       return error(_("daemon did not stop within %d seconds"),
+                                    max_wait_ms / 1000);
+               }
                sleep_millisec(50);
+               elapsed_ms += 50;
+       }
        trace2_region_leave("fsm_client", "polling-for-daemon-exit", NULL);
 
        return 0;