spacedriveapp / spacedriveapp/spacebot

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

Open Beginner friendly
#559 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
2.4k
Forks
367
PR merge metrics
No merged PRs in 30d

Description

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

  • The cleanup_stale_files logic was pre-existing Unix-only code; this PR (#558) only reorganised it into unix_impl without changing its logic. Improving it was intentionally deferred to keep that PR's scope focused on Windows/sidecar fixes.
  • Raised by @coderabbitai in PR #558: https://github.com/spacedriveapp/spacebot/pull/558#discussion_r3068529186
  • Requested by @slvnlrt

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read AGENTS.md and inspect the cleanup paths in src/daemon.rs: unix_impl::cleanup_stale_files and the shutdown task in unix_impl::start_ipc_server. Handle remove_file errors without logging expected NotFound failures, and verify that other cleanup errors include the path and are logged as warnings.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
operating-systems
Issue type
Refactor
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.