fix(handler/serial,sni): 5 code-review fixes - xnet.Pipe errors, (nil,nil) warning, readTimeout comment, defer deadline, clean close
- serial/handler.go: capture xnet.Pipe return value in Handle() and forwardSerial() - serial/handler.go: log Warnf when chain dial returns (nil,nil) before falling back - sni/handler.go: use defer for read deadline reset to prevent stale deadline - sni/handler.go: unrecognized protocol returns nil (clean close) instead of error - sni/metadata.go: update readTimeout comment to reflect dual usage (deadline + SnifferBuilder)
This commit is contained in:
@@ -122,12 +122,10 @@ func (h *sniHandler) Handle(ctx context.Context, conn net.Conn, opts ...handler.
|
||||
|
||||
if h.md.readTimeout > 0 {
|
||||
conn.SetReadDeadline(time.Now().Add(h.md.readTimeout))
|
||||
defer conn.SetReadDeadline(time.Time{})
|
||||
}
|
||||
br := bufio.NewReader(conn)
|
||||
proto, sniffErr := sniffing.Sniff(ctx, br)
|
||||
if h.md.readTimeout > 0 {
|
||||
conn.SetReadDeadline(time.Time{})
|
||||
}
|
||||
if sniffErr != nil {
|
||||
log.Debugf("sniff: %v", sniffErr)
|
||||
}
|
||||
@@ -189,7 +187,8 @@ func (h *sniHandler) Handle(ctx context.Context, conn net.Conn, opts ...handler.
|
||||
sniffing.WithLog(log),
|
||||
)
|
||||
default:
|
||||
return errors.New("unknown traffic")
|
||||
log.Debugf("unrecognized traffic from %s", conn.RemoteAddr())
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,11 +13,11 @@ import (
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
// readTimeout is passed to SnifferBuilder as the timeout for reading
|
||||
// upstream response headers during HTTP/TLS sniffing. It is NOT used
|
||||
// as a deadline on the initial client connection (unlike socks/ss
|
||||
// handlers), because SNI routing has no protocol handshake beyond
|
||||
// the TLS ClientHello which is parsed during sniffing.
|
||||
// readTimeout controls two behaviors:
|
||||
// 1. A read deadline set on the client connection before sniffing the
|
||||
// TLS ClientHello / HTTP request (see handler.go Handle).
|
||||
// 2. Passed to SnifferBuilder as the timeout for reading upstream
|
||||
// response headers during HTTP/TLS sniffing.
|
||||
// 0 or negative defaults to 15s.
|
||||
readTimeout time.Duration
|
||||
hash string
|
||||
|
||||
Reference in New Issue
Block a user