fsmonitor: add timeout to daemon stop command

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>

Paul Tarjan committed Apr 15, 2026 at 13:27 UTC 1cbfa62766d04eee86d8cf0f0efe1c344e73591a
1 file changed +11 -1
builtin/fsmonitor--daemon.c
+11 -1
@@ -86,6 +86,8 @@ static int do_as_client__send_stop(void)
86 {
87 struct strbuf answer = STRBUF_INIT;
88 int ret;
89 + int max_wait_ms = 30000;
90 + int elapsed_ms = 0;
91
92 ret = fsmonitor_ipc__send_command("quit", &answer);
93
@@ -96,8 +98,16 @@ static int do_as_client__send_stop(void)
98 return ret;
99
100 trace2_region_enter("fsm_client", "polling-for-daemon-exit", NULL);
99 - while (fsmonitor_ipc__get_state() == IPC_STATE__LISTENING)
101 + while (fsmonitor_ipc__get_state() == IPC_STATE__LISTENING) {
102 + if (elapsed_ms >= max_wait_ms) {
103 + trace2_region_leave("fsm_client",
104 + "polling-for-daemon-exit", NULL);
105 + return error(_("daemon did not stop within %d seconds"),
106 + max_wait_ms / 1000);
107 + }
108 sleep_millisec(50);
109 + elapsed_ms += 50;
110 + }
111 trace2_region_leave("fsm_client", "polling-for-daemon-exit", NULL);
112
113 return 0;