diff --git a/internal/socket_unix.go b/internal/socket_unix.go index a817a2e9..b733d861 100644 --- a/internal/socket_unix.go +++ b/internal/socket_unix.go @@ -156,7 +156,13 @@ func connect(fd int, remoteAddr net.Addr, timeout time.Duration, opts ...sonicop return os.NewSyscallError("getsockopt", err) } if socketErr != 0 { - return syscall.Errno(socketErr) + var err error = syscall.Errno(socketErr) + if errors.Is(err, syscall.ECONNREFUSED) { + // This is the most likely to happen and on which callers will have custom logic. The rest we can just + // propagate. + return sonicerrors.ErrConnRefused + } + return err } } diff --git a/sonicerrors/errors.go b/sonicerrors/errors.go index 13f7059f..8b4102e2 100644 --- a/sonicerrors/errors.go +++ b/sonicerrors/errors.go @@ -8,4 +8,5 @@ var ( ErrTimeout = errors.New("operation timed out") ErrNeedMore = errors.New("need to read/write more bytes") ErrNoBufferSpaceAvailable = errors.New("no buffer space available") + ErrConnRefused = errors.New("connection refused") // a connect() on a stream socket found no one listening on the remote address )