Skip to content

Commit

Permalink
Add custom error type for ECONNREFUSED
Browse files Browse the repository at this point in the history
  • Loading branch information
sergiu128 committed Nov 27, 2024
1 parent 32aaa2e commit 7f1dd39
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion internal/socket_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
1 change: 1 addition & 0 deletions sonicerrors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

0 comments on commit 7f1dd39

Please sign in to comment.