mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-01-21 16:26:36 +00:00
Mixed inbound: Handle immediately closing connection gracefully (#4297)
Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com>
This commit is contained in:
parent
66dd7808b6
commit
30cb22afb1
|
@ -2,6 +2,7 @@ package socks
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
goerrors "errors"
|
||||||
"io"
|
"io"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -78,7 +79,13 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn stat.Con
|
||||||
switch network {
|
switch network {
|
||||||
case net.Network_TCP:
|
case net.Network_TCP:
|
||||||
firstbyte := make([]byte, 1)
|
firstbyte := make([]byte, 1)
|
||||||
conn.Read(firstbyte)
|
if n, err := conn.Read(firstbyte); n == 0 {
|
||||||
|
if goerrors.Is(err, io.EOF) {
|
||||||
|
errors.LogInfo(ctx, "Connection closed immediately, likely health check connection")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return errors.New("failed to read from connection").Base(err)
|
||||||
|
}
|
||||||
if firstbyte[0] != 5 && firstbyte[0] != 4 { // Check if it is Socks5/4/4a
|
if firstbyte[0] != 5 && firstbyte[0] != 4 { // Check if it is Socks5/4/4a
|
||||||
errors.LogDebug(ctx, "Not Socks request, try to parse as HTTP request")
|
errors.LogDebug(ctx, "Not Socks request, try to parse as HTTP request")
|
||||||
return s.httpServer.ProcessWithFirstbyte(ctx, network, conn, dispatcher, firstbyte...)
|
return s.httpServer.ProcessWithFirstbyte(ctx, network, conn, dispatcher, firstbyte...)
|
||||||
|
|
Loading…
Reference in a new issue