Skip to content

Commit 30cb22a

Browse files
rPDmYQRPRX
andauthored
Mixed inbound: Handle immediately closing connection gracefully (#4297)
Co-authored-by: RPRX <[email protected]>
1 parent 66dd780 commit 30cb22a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

proxy/socks/server.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package socks
22

33
import (
44
"context"
5+
goerrors "errors"
56
"io"
67
"time"
78

@@ -78,7 +79,13 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn stat.Con
7879
switch network {
7980
case net.Network_TCP:
8081
firstbyte := make([]byte, 1)
81-
conn.Read(firstbyte)
82+
if n, err := conn.Read(firstbyte); n == 0 {
83+
if goerrors.Is(err, io.EOF) {
84+
errors.LogInfo(ctx, "Connection closed immediately, likely health check connection")
85+
return nil
86+
}
87+
return errors.New("failed to read from connection").Base(err)
88+
}
8289
if firstbyte[0] != 5 && firstbyte[0] != 4 { // Check if it is Socks5/4/4a
8390
errors.LogDebug(ctx, "Not Socks request, try to parse as HTTP request")
8491
return s.httpServer.ProcessWithFirstbyte(ctx, network, conn, dispatcher, firstbyte...)

0 commit comments

Comments
 (0)