fix: apply idle timeout to domain fronting relay#416
Merged
9seconds merged 4 commits into9seconds:masterfrom Mar 29, 2026
Merged
fix: apply idle timeout to domain fronting relay#4169seconds merged 4 commits into9seconds:masterfrom
9seconds merged 4 commits into9seconds:masterfrom
Conversation
Domain fronting relay (for non-Telegram traffic) had no idle timeout, causing worker pool exhaustion under traffic spikes. The ProxyOpts.IdleTimeout field existed but was never wired into the proxy. Now domain fronting connections are wrapped with per-read/write deadlines reset to the configured idle timeout (default 1m), so stale or slowloris-style connections are reaped promptly. Fixes 9seconds#378
When the worker pool rejected a connection (ErrPoolOverload), the accepted net.Conn was never closed — leaking a file descriptor and TCP socket per rejected connection. Under sustained traffic spikes this compounds the problem: leaked descriptors reduce the capacity for new dials (including to the fronting domain), accelerating the failure cascade described in 9seconds#378.
- avoid deprecated DefaultIdleTimeout, use time.Minute directly - simplify embedded field selectors (QF1008)
This was referenced Mar 28, 2026
dolonet
added a commit
to dolonet/mtg-multi
that referenced
this pull request
Mar 29, 2026
Wrap both sides of the Telegram relay in connIdleTimeout, same as already done for domain fronting in 9seconds#416. Without this, if a client disappears (network drop, battery dies), the TCP connection stays formally alive and the goroutine in the worker pool blocks on io.CopyBuffer indefinitely. Under mass client disconnects this accumulates zombie goroutines. Fixes 9seconds#417
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #378 — two bugs that together cause proxy failure under non-Telegram traffic spikes.
1. Domain fronting relay has no idle timeout
ProxyOpts.IdleTimeoutwas defined but never wired into the proxy. ThedoDomainFrontingrelay used rawio.CopyBufferwith no deadline, so each forwarded connection could block a worker goroutine indefinitely. Under a burst of probes/scanners/slowloris the pool fills up and legitimate Telegram connections get dropped.Fix: wrap both sides of the domain fronting relay in a
connIdleTimeoutadapter that resets read/write deadlines on every I/O operation. The timeout comes fromnetwork.timeout.idleconfig (default 1m).2. Connection leak on worker pool overflow
When the pool rejected a connection (
ErrPoolOverload), the acceptednet.Connwas never closed — leaking a file descriptor and TCP socket per rejected connection. Under sustained spikes this compounds the problem: leaked descriptors reduce capacity for new dials (including to the fronting domain).Fix:
conn.Close()before logging the concurrency limit event, consistent with the blocklist/allowlist paths.Changes
mtglib/conns.go— addconnIdleTimeoutwrappermtglib/proxy.go— storeidleTimeoutin Proxy; wrap domain fronting relay connections; close conn on pool overflowmtglib/proxy_opts.go— addgetIdleTimeout()with default fallbackinternal/cli/run_proxy.go— passconf.Network.Timeout.IdleintoProxyOpts