Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxMaeder authored Nov 27, 2024
2 parents 9548b92 + 7f1dd39 commit 12b77a6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion internal/socket_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,19 @@ func connect(fd int, remoteAddr net.Addr, timeout time.Duration, opts ...sonicop
return sonicerrors.ErrTimeout
}

_, err = syscall.GetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_ERROR)
socketErr, err := syscall.GetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_ERROR)
if err != nil {
return os.NewSyscallError("getsockopt", err)
}
if socketErr != 0 {
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
}
}

return nil
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 12b77a6

Please sign in to comment.