Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Commit 597e39b

Browse files
author
Juanjo Alvarez
committed
Fail on all socket connection close state or early closing
Signed-off-by: Juanjo Alvarez <[email protected]>
1 parent 92ab81b commit 597e39b

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

internal/sockstate/netstat_darwin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212
// elements that satisfy the accept function
1313
func tcpSocks(accept AcceptFn) ([]sockTabEntry, error) {
1414
// (juanjux) TODO: not implemented
15-
logrus.Info("Connection checking not implemented for Darwin")
16-
return []sockTabEntry{}, nil
15+
logrus.Info("Connection checking not implemented for Windows")
16+
return nil, ErrSocketCheckNotImplemented.New()
1717
}
1818

1919
func GetConnInode(c *net.TCPConn) (n uint64, err error) {

internal/sockstate/netstat_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
func tcpSocks(accept AcceptFn) ([]sockTabEntry, error) {
1414
// (juanjux) TODO: not implemented
1515
logrus.Info("Connection checking not implemented for Windows")
16-
return []sockTabEntry{}, nil
16+
return nil, ErrSocketCheckNotImplemented.New()
1717
}
1818

1919
func GetConnInode(c *net.TCPConn) (n uint64, err error) {

internal/sockstate/sockstate.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import (
88
type SockState uint8
99

1010
const (
11-
Finished = iota
12-
Broken
11+
Broken = iota
1312
Other
1413
Error
1514
)
@@ -37,12 +36,24 @@ func GetInodeSockState(port int, inode uint64) (SockState, error) {
3736

3837
switch len(socks) {
3938
case 0:
40-
return Finished, nil
39+
fallthrough
4140
case 1:
42-
if socks[0].State == CloseWait {
41+
switch socks[0].State {
42+
case CloseWait:
43+
fallthrough
44+
case TimeWait:
45+
fallthrough
46+
case FinWait1:
47+
fallthrough
48+
case FinWait2:
49+
fallthrough
50+
case Close:
51+
fallthrough
52+
case Closing:
4353
return Broken, nil
54+
default:
55+
return Other, nil
4456
}
45-
return Other, nil
4657
default: // more than one sock for inode, impossible?
4758
return Error, ErrMultipleSocketsForInode.New()
4859
}

server/handler.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,16 +211,12 @@ func (h *Handler) ComQuery(
211211
for {
212212
select {
213213
case <-quit:
214-
// timeout or other errors detected by the calling routine
215214
return
216215
default:
217216
}
218217

219218
st, err := sockstate.GetInodeSockState(t.Port, inode)
220219
switch st {
221-
case sockstate.Finished:
222-
// Not Linux OSs will also exit here
223-
return
224220
case sockstate.Broken:
225221
errChan <- ErrConnectionWasClosed.New()
226222
return

0 commit comments

Comments
 (0)