spacedriveapp / spacedriveapp/spacebot
refactor(daemon): log errors in cleanup_stale_files and shutdown socket removal
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:
unix_impl::cleanup_stale_files– uses barelet _ = std::fs::remove_file(...)for both the PID file and the socket file.- The
tokio::spawnshutdown task inunix_impl::start_ipc_server– useslet _ = 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_fileslogic was pre-existing Unix-only code; this PR (#558) only reorganised it intounix_implwithout 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read AGENTS.md, then inspect src/daemon.rs at unix_impl::cleanup_stale_files and unix_impl::start_ipc_server. Replace the silent remove_file Results with the described warning behavior while ignoring expected NotFound errors. Done means all three cleanup calls handle errors without let _ and include useful paths in warnings.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- backend, operating-systems
- Issue type
- Refactor
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100