Skip to content

Commit 84d576a

Browse files
authored
internal/sockstate: Restore connection checking on Linux. (#2722)
GMS server handler is supposed to cancel running queries if the connection which issued them goes away. It does this by checking the connection state out-of-band anytime the query is running and canceling theh query if the connection goes away. The connection checking code is platform-specific and currently only works on Linux. In commit 538696b I introduced a bug where the connection checking code tries to inspect the socket state of an already closed file descriptor. This change fixes the behavior so that the file descriptor is left open until the necessary socket state is extracted.
1 parent a6e78e0 commit 84d576a

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

internal/sockstate/netstat_darwin.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ func tcpSocks(accept AcceptFn) ([]sockTabEntry, error) {
3232
}
3333

3434
func GetConnInode(c *net.TCPConn) (uint64, error) {
35-
_, err := getConnFd(c)
35+
_, finalize, err := getConnFd(c)
3636
if err != nil {
3737
return 0, err
3838
}
39+
defer finalize()
3940
return 0, ErrSocketCheckNotImplemented.New()
4041
}

internal/sockstate/netstat_freebsd.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@ func tcpSocks(accept AcceptFn) ([]sockTabEntry, error) {
3232
}
3333

3434
func GetConnInode(c *net.TCPConn) (uint64, error) {
35-
_, err := getConnFd(c)
35+
_, finalize, err := getConnFd(c)
3636
if err != nil {
3737
return 0, err
3838
}
39+
defer finalize()
3940
return 0, ErrSocketCheckNotImplemented.New()
4041
}

internal/sockstate/netstat_linux.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,10 +279,11 @@ func tcpSocks(accept AcceptFn) ([]sockTabEntry, error) {
279279

280280
// GetConnInode returns the inode number of an fd.
281281
func GetConnInode(conn *net.TCPConn) (n uint64, err error) {
282-
fd, err := getConnFd(conn)
282+
fd, finalize, err := getConnFd(conn)
283283
if err != nil {
284284
return 0, err
285285
}
286+
defer finalize()
286287

287288
if isWSL || isProcBlocked {
288289
return 0, ErrSocketCheckNotImplemented.New()

internal/sockstate/netstat_unix.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ import (
2222
"syscall"
2323
)
2424

25-
func getConnFd(c *net.TCPConn) (fd uintptr, err error) {
25+
func getConnFd(c *net.TCPConn) (fd uintptr, finalize func() error, err error) {
2626
f, err := c.File()
2727
if err != nil {
28-
return 0, err
28+
return 0, nil, err
2929
}
3030

3131
fd = f.Fd()
@@ -34,7 +34,5 @@ func getConnFd(c *net.TCPConn) (fd uintptr, err error) {
3434
// blocking Close() in some cases.
3535
syscall.SetNonblock(int(fd), true)
3636

37-
f.Close()
38-
39-
return fd, nil
37+
return fd, f.Close, nil
4038
}

0 commit comments

Comments
 (0)