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:
ginuerzh
2026-06-05 21:09:10 +08:00
parent f09a7a69b3
commit 4d4690b535
3 changed files with 21 additions and 11 deletions
+3 -4
View File
@@ -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
}
}