Fix pipe cleanup logic during shutdown to handle ENOENT case (#22509)
* Fix pipe cleanup logic during shutdown to handle ENOENT case - Updated `unlink()` logic to avoid logging errors when the pipe is already removed by libuv in certain exit paths. * Improve comment code Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Stelios Fragkakis committed
May 20, 2026 at 17:50 UTC
225d72660cc691abadf07e71d9bf4d680660e753
1 file changed
+5
-1
src/daemon/daemon-shutdown.c
+5
-1
@@ -326,8 +326,12 @@ static void netdata_cleanup_and_exit(EXIT_REASON reason, bool abnormal, bool exi
326
netdata_log_error("EXIT: cannot unlink pidfile '%s'.", pidfile);
327
328
// unlink the pipe
329
+ // During the commands_exit() signal-handler path, libuv may already
330
+ // have unlinked the pipe on close. For other exit paths the command
331
+ // thread keeps running and we must clean it up here. ENOENT just means
332
+ // libuv beat us to removing it.
333
const char *pipe = daemon_pipename();
330
- if(pipe && *pipe && unlink(pipe) != 0)
334
+ if(pipe && *pipe && unlink(pipe) != 0 && errno != ENOENT)
335
netdata_log_error("EXIT: cannot unlink netdatacli socket file '%s'.", pipe);
336
337
watcher_step_complete(WATCHER_STEP_ID_REMOVE_PID_FILE);