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>
This commit is contained in:
Quheng DengandWengeLiu101 authored and GitHub committed 2026-10-23 09:25:00 +08:00
1 parent 05874a5bf0
commit 57b906b23f
1 file changed
+12 -1
+12 -1
View File
@@ -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)
}