Skip to content

refactor(daemon): log errors in cleanup_stale_files and shutdown socket removal #559

@coderabbitai

Description

@coderabbitai

Summary

In src/daemon.rs, two cleanup paths currently silently discard remove_file errors, making stale PID/socket problems harder to diagnose on the next launch:

  1. unix_impl::cleanup_stale_files – uses bare let _ = std::fs::remove_file(...) for both the PID file and the socket file.
  2. The tokio::spawn shutdown task in unix_impl::start_ipc_server – uses let _ = std::fs::remove_file(&cleanup_socket) after the shutdown signal is received.

Per the project coding guidelines (AGENTS.md): Don't silently discard errors. No let _ = on Results. Handle them, log them, or propagate them.

Suggested fix

     tokio::spawn(async move {
         let _ = cleanup_rx.wait_for(|shutdown| *shutdown).await;
-        let _ = std::fs::remove_file(&cleanup_socket);
+        if let Err(error) = std::fs::remove_file(&cleanup_socket)
+            && error.kind() != std::io::ErrorKind::NotFound
+        {
+            tracing::warn!(
+                %error,
+                path = %cleanup_socket.display(),
+                "failed to remove IPC socket on shutdown"
+            );
+        }
     });

     fn cleanup_stale_files(paths: &DaemonPaths) {
-        let _ = std::fs::remove_file(&paths.pid_file);
-        let _ = std::fs::remove_file(&paths.socket);
+        for path in [&paths.pid_file, &paths.socket] {
+            if let Err(error) = std::fs::remove_file(path)
+                && error.kind() != std::io::ErrorKind::NotFound
+            {
+                tracing::warn!(%error, path = %path.display(), "failed to remove stale daemon file");
+            }
+        }
     }

Context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions