VictoriaMetrics/VictoriaMetrics · error
cannot dial socket path %q: %w
Error message
cannot dial socket path %q: %w
What it means
removePreviousSocketFile dials the existing socket path to test liveness; any dial error other than ENOENT or ECONNREFUSED (e.g. EACCES — access denied) is not safely interpretable, so it is wrapped and returned instead of unlinking the file. This prevents deleting a socket that might belong to a running process the caller cannot even probe.
Source
Thrown at lib/netutil/unixlistener.go:71
return fmt.Errorf("file %q already exists and is not a socket", addr)
}
conn, err := net.DialTimeout("unix", addr, 100*time.Millisecond)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
// File does not exist.
return nil
}
if errors.Is(err, syscall.ECONNREFUSED) {
// File exists, but there is no listener.
// This may happen in case of unclean shutdown, so remove it.
if err := os.Remove(addr); err != nil {
return fmt.Errorf("cannot remove exist socket path: %w", err)
}
return nil
}
// Could be access denied or other unrelated errors.
return fmt.Errorf("cannot dial socket path %q: %w", addr, err)
}
_ = conn.Close()
return fmt.Errorf("another process is already listening on %q", addr)
}
// UnixListener listens for the addr passed to NewUnixListener.
//
// It also gathers various stats for the accepted connections.
type UnixListener struct {
*net.UnixListener
accepts *metrics.Counter
acceptErrors *metrics.Counter
cm connMetrics
}
// Accept accepts connections from the addr passed to NewUnixListener.View on GitHub (pinned to 5079fb58f1)
Solutions
- Inspect the wrapped %w error (often 'connect: permission denied')
- Fix permissions so the current user can access the socket path and its parent directories (chmod/chown)
- Remove the socket file manually if you are certain no process is using it
- Run the process under the same user that created the previous socket
Example fix
// before $ ls -l /run/vm.sock # srw------- root root $ ./victoria-metrics -unixListenAddr /run/vm.sock # EACCES // after $ sudo rm /run/vm.sock # or chown/chmod so the service user can access it
Defensive patterns
Strategy: try-catch
Validate before calling
import "net"
import "os"
import "time"
func socketIsAccessible(addr string) error {
if _, err := os.Lstat(addr); err != nil {
return nil // no file, nothing to probe
}
conn, err := net.DialTimeout("unix", addr, 100*time.Millisecond)
if err != nil {
return nil // will be handled by the library (refused/not-exist)
}
conn.Close()
return fmt.Errorf("already listening on %s", addr)
} Try / catch
ln, err := netutil.NewUnixListener(sockPath)
if err != nil {
if strings.Contains(err.Error(), "cannot dial socket path") {
var se syscall.Errno
if errors.As(err, &se) && se == syscall.EACCES {
log.Fatalf("no permission to probe %s; fix socket/dir ownership", sockPath)
}
}
return err
} Prevention
- Run the service as the same user that previously created the socket
- Grant traverse (x) permission on all parent directories of the socket path
- Check SELinux/AppArmor audit logs if permissions look correct
- Prefer a per-service socket directory owned by the service user
When it happens
Trigger: NewUnixListener is called with an addr where a socket file exists but net.DialTimeout fails with a non-ENOENT/non-ECONNREFUSED error — most commonly EACCES because the current user cannot read/write the socket file or traverse its directory.
Common situations: Socket created by another user or in a directory with restrictive permissions, AppArmor/SELinux denials, or a socket under a path with no execute permission for the current user.
Related errors
- cannot set permissions for socket path %q: %w
- cannot remove exist socket path: %w
- cannot delete `backup complete` file at %s: %w
- cannot open directory: %w
- cannot append files %q: %w
AI-assisted analysis of VictoriaMetrics/VictoriaMetrics@5079fb58f1 (2026-09-03).
Data as JSON: /api/errors/07ab5423e25c16d7.
Report an issue: GitHub.