fix(handler/forward): split readTimeout from pipe idleTimeout to prevent 15s download abort

The readTimeout field (default 15s) was being applied via xnet.Pipe to both
directions of a bidirectional proxy connection. During asymmetric transfers
(e.g. HTTP file download), the direction reading from the tunnel sees no
data after the initial request is forwarded, causing SetReadDeadline to fire
after 15s and abort the entire transfer.

Fix: add a separate idleTimeout field (default 0=disabled) to the metadata
structs in both forward/local and forward/remote handlers, and switch
xnet.Pipe to use idleTimeout instead of readTimeout. The readTimeout field
now only applies to the initial protocol sniffing/handshake phase.

Also document readTimeout vs idleTimeout semantics across all 24 locations
in the x/ module where these timeouts appear:
- readTimeout: handshake sniffing deadline (handlers), upstream response
  header timeout (http.Transport), or transport-level read deadline
- idleTimeout: idle read deadline per Pipe direction (0=disabled)
- ReadTimeout on Sniffer/SnifferBuilder: upstream response header/TLS
  handshake read timeout during sniffing
This commit is contained in:
ginuerzh
2026-05-31 17:05:21 +08:00
parent b8d9c79f72
commit 722dde5cfc
24 changed files with 128 additions and 6 deletions
+3
View File
@@ -63,6 +63,9 @@ type entrypoint struct {
sniffingWebsocket bool
websocketSampleRate float64
// readTimeout is applied as SetReadDeadline on the upstream connection
// before sniffing HTTP/TLS reads. It mirrors entryPointReadTimeout
// from the handler metadata.
readTimeout time.Duration
}
+5 -1
View File
@@ -21,6 +21,10 @@ const (
)
type metadata struct {
// readTimeout is the deadline for reading the initial relay protocol
// handshake from the client connection. The deadline is cleared
// after the handshake, so it does not affect subsequent data
// transfer. 0 or negative means no timeout is applied.
readTimeout time.Duration
entrypoints []entrypointConfig
@@ -30,7 +34,7 @@ type metadata struct {
entryPointProxyProtocol int
entryPointKeepalive bool
entryPointCompression bool
entryPointReadTimeout time.Duration
entryPointReadTimeout time.Duration // deadline for reading upstream HTTP response headers in the entrypoint's http.Transport.ResponseHeaderTimeout. Also passed as readTimeout to entrypoint dialer for SetReadDeadline on upstream conn. 0 or negative defaults to 15s.
sniffingWebsocket bool
sniffingWebsocketSampleRate float64