From 57b906b23fbecf3eed12297883a9e3bbf44e1493 Mon Sep 17 00:00:00 2001 From: Quheng Deng Date: Fri, 23 Oct 2026 09:25:00 +0800 Subject: [PATCH] fix(proxy): treat any failed probe as a proxy failure, not just timeouts (#111) checkClaimedProxy() only marked a proxy unhealthy when the probe error was a timeout or ECONNREFUSED (isProxyFailure). A proxy that answers the CONNECT with its own error -- e.g. a provider refusing because the plan's bandwidth is exhausted -- produced an error matching none of those cases, so the probe was reported as inconclusive and the proxy stayed healthy forever: never taken out of rotation and never re-bound for key traffic. A probe is a plain HTTP GET issued through the proxy; if it returns no response, that proxy cannot serve traffic, whatever the reason. Count every non-cancellation error as a failure. context.Canceled stays exempt because it says the caller gave up, not that the proxy is down. Scope: the probe path only. syncProxyResult() (real traffic) and the anonymous attempt loop keep using isProxyFailure deliberately -- there an error may come from the upstream rather than the proxy, so staying conservative is correct. Co-authored-by: WengeLiu101 <233876084+WengeLiu101@users.noreply.github.com> --- internal/gateway/pool.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/internal/gateway/pool.go b/internal/gateway/pool.go index e03226a..a7182c9 100644 --- a/internal/gateway/pool.go +++ b/internal/gateway/pool.go @@ -558,7 +558,18 @@ func (p *proxyTransports) checkClaimedProxy(ctx context.Context, proxy *proxyTra result := proxyHealthResult{proxy: proxy, err: err, wasHealthy: proxy.healthy.Load()} if err == nil { result.wasHealthy = proxy.healthy.Swap(true) - } else if isProxyFailure(err) { + } else if !errors.Is(err, context.Canceled) { + // A probe is a plain HTTP GET issued *through* the proxy. If it did not + // return a response, this proxy cannot currently serve traffic — the + // CONNECT was refused, the tunnel broke, the connection was reset, or it + // timed out. Every such outcome must count as a failure. + // + // isProxyFailure() only recognized timeouts and ECONNREFUSED, so a proxy + // whose CONNECT is rejected for any other reason (a provider refusing + // with its own error, e.g. an exhausted-bandwidth response) was reported + // as "inconclusive". It then stayed healthy forever: never taken out of + // rotation, never re-bound for key traffic. Only cancellation is exempt, + // because that says the *caller* gave up, not that the proxy is down. result.failed = true result.wasHealthy = proxy.healthy.Swap(false) }