Skip to content

Commit ec009fc

Browse files
ptarjangitster
authored andcommitted
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>
1 parent ec4e5b9 commit ec009fc

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

builtin/fsmonitor--daemon.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ static int do_as_client__send_stop(void)
8686
{
8787
struct strbuf answer = STRBUF_INIT;
8888
int ret;
89+
int max_wait_ms = 30000;
90+
int elapsed_ms = 0;
8991

9092
ret = fsmonitor_ipc__send_command("quit", &answer);
9193

@@ -96,8 +98,16 @@ static int do_as_client__send_stop(void)
9698
return ret;
9799

98100
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+
}
100108
sleep_millisec(50);
109+
elapsed_ms += 50;
110+
}
101111
trace2_region_leave("fsm_client", "polling-for-daemon-exit", NULL);
102112

103113
return 0;

0 commit comments

Comments
 (0)