Skip to content

Commit 4cd9853

Browse files
committed
fix(connCheck): don't block on peeking
1 parent 1e2df9f commit 4cd9853

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

internal/pool/conn_check.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"net"
99
"syscall"
1010
"time"
11-
"unsafe"
1211
)
1312

1413
var errUnexpectedRead = errors.New("unexpected read from socket")
@@ -34,24 +33,17 @@ func connCheck(conn net.Conn) error {
3433
if err := rawConn.Read(func(fd uintptr) bool {
3534
var buf [1]byte
3635
// Use MSG_PEEK to peek at data without consuming it
37-
n, _, errno := syscall.Syscall6(
38-
syscall.SYS_RECVFROM,
39-
fd,
40-
uintptr(unsafe.Pointer(&buf[0])),
41-
1,
42-
syscall.MSG_PEEK, // This ensures the byte stays in the socket buffer
43-
0, 0,
44-
)
36+
n, _, err := syscall.Recvfrom(int(fd), buf[:], syscall.MSG_PEEK|syscall.MSG_DONTWAIT)
4537

4638
switch {
47-
case n == 0 && errno == 0:
39+
case n == 0 && err == nil:
4840
sysErr = io.EOF
4941
case n > 0:
5042
sysErr = errUnexpectedRead
51-
case errno == syscall.EAGAIN || errno == syscall.EWOULDBLOCK:
43+
case err == syscall.EAGAIN || err == syscall.EWOULDBLOCK:
5244
sysErr = nil
5345
default:
54-
sysErr = errno
46+
sysErr = err
5547
}
5648
return true
5749
}); err != nil {

0 commit comments

Comments
 (0)