matcha
matcha copied to clipboard
BUG: Unchecked os.Remove() when cleaning stale daemon socket
Describe the bug In daemon/daemon.go line 89, os.Remove() is called to clean stale socket file but error is ignored. If removal fails due to permissions, subsequent Listen() will fail with confusing error.
To reproduce
- Examine daemon/daemon.go lines 87-94:
// Remove stale socket file.
sockPath := daemonrpc.SocketPath()
os.Remove(sockPath) // Error ignored
// Listen on Unix domain socket.
var err error
d.listener, err = net.Listen("unix", sockPath)
if err != nil {
return fmt.Errorf("listen: %w", err)
}
- If socket file exists but can't be removed (permissions), Listen fails with "address already in use"
Expected behavior Two options:
- Check error and return if removal fails (safer)
- Explicitly ignore with
_ = os.Remove()to document intentional ignore (for cleanup where failure is acceptable)
Additional context
- Good first issue: simple error handling decision
- Low severity (cleanup operation)
- Similar pattern in main.go line 3282 uses
_ = os.Remove()to explicitly ignore - Related to issue about unchecked os.Chmod() on line 100
Suggested fix (option 1 - check):
// Remove stale socket file.
sockPath := daemonrpc.SocketPath()
if err := os.Remove(sockPath); err != nil && !os.IsNotExist(err) {
return fmt.Errorf("failed to remove stale socket: %w", err)
}
Suggested fix (option 2 - explicit ignore):
// Remove stale socket file (ignore errors).
sockPath := daemonrpc.SocketPath()
_ = os.Remove(sockPath)
OS Unix-like systems (Linux, macOS, BSD)
This has had no activity for 30 days. It will be closed in 14 days unless updated. Comment or remove the stale label to keep it open.