Files
x/handler/ss/udp/metadata.go
T
ginuerzh 722dde5cfc 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
2026-05-31 17:05:21 +08:00

47 lines
1.1 KiB
Go

package ss
import (
"time"
mdata "github.com/go-gost/core/metadata"
"github.com/go-gost/go-shadowsocks2/core"
mdutil "github.com/go-gost/x/metadata/util"
)
const (
defaultBufferSize = 4096
)
type metadata struct {
key string
// readTimeout is the deadline for reading a single UDP datagram from
// the client. Since UDP is connectionless, this timeout applies to
// each individual datagram read. Default: 1 minute (longer than the
// typical 15s used by TCP handlers to accommodate the stateless
// nature of UDP).
readTimeout time.Duration
udpBufferSize int
users []core.UserConfig
}
func (h *ssuHandler) parseMetadata(md mdata.Metadata) (err error) {
h.md.key = mdutil.GetString(md, "key")
h.md.readTimeout = mdutil.GetDuration(md, "readTimeout")
if h.md.readTimeout == 0 {
h.md.readTimeout = time.Minute // Default read timeout
}
h.md.udpBufferSize = mdutil.GetInt(md, "udpBufferSize", "udp.bufferSize")
usersMap := mdutil.GetStringMapString(md, "users")
for name, pass := range usersMap {
h.md.users = append(h.md.users, core.UserConfig{
Name: name,
Password: pass,
})
}
return
}