matcha icon indicating copy to clipboard operation
matcha copied to clipboard

BUG: Unchecked os.Remove() when cleaning stale daemon socket

Open andrinoff opened this issue 7 months ago • 1 comments

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

  1. 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)
}
  1. If socket file exists but can't be removed (permissions), Listen fails with "address already in use"

Expected behavior Two options:

  1. Check error and return if removal fails (safer)
  2. 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)

andrinoff avatar Apr 21 '26 09:04 andrinoff

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.

floatpanebot avatar May 22 '26 06:05 floatpanebot