Skip to content

fix(proxy): a probe that returns no response must fail the proxy, not just timeouts and refusals - #111

Merged
jasonxu114514 merged 1 commit into
jasonxu114514:mainfrom
WengeLiu101:fix/proxy-probe-failure-classification
Oct 23, 2026
Merged

jasonxu114514 merged 1 commit into
jasonxu114514:mainfrom
WengeLiu101:fix/proxy-probe-failure-classification

Conversation

@WengeLiu101

Copy link
Copy Markdown
Contributor

Problem

checkClaimedProxy() decides a proxy's health from a probe — a plain HTTP GET issued through the proxy.
When the probe returns no response, the failure is classified by isProxyFailure(), which recognizes only
context.DeadlineExceeded, syscall.ECONNREFUSED and deadline timeouts. Everything else is reported as
health_check_inconclusive and leaves the proxy marked healthy.

That misses the failure a metered proxy pool produces most often: the proxy accepts the TCP connection and then
answers the CONNECT with its own error — an exhausted-bandwidth / quota response, a provider-side tunnel error,
a reset. The proxy is unusable but stays "healthy" forever: never taken out of rotation, never re-bound for key
traffic. The pool keeps handing it out and every request through it fails.

Fix

A probe that returns no response means the proxy cannot currently serve traffic, whatever the reason.

 	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) {
 		result.failed = true
 		result.wasHealthy = proxy.healthy.Swap(false)
 	}

context.Canceled stays exempt: 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 can originate upstream rather than from the proxy, so staying
conservative is right. isProxyFailure therefore stays in use and does not become dead code.

Verification

Measured on a local build (v1.4.0 + this change) with a pool of 60 proxies whose CONNECT is answered with the
provider's bandwidth error (TCP connects, CONNECT never completes):

before after
checkClaimedProxy outcome health_check_inconclusive failed
proxies marked unhealthy after one probe round 1 60

isProxyFailure and checkClaimedProxy are byte-identical on main to the v1.4.0 I measured against, so the
same code path applies here.

Notes

  • No config or API change; behaviour change is confined to when a proxy is marked unhealthy.
  • A proxy that answers HTTP (even 4xx/5xx) is unaffected — the probe only fails on "no response".

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.
@jasonxu114514
jasonxu114514 merged commit 57b906b into jasonxu114514:main Oct 23, 2026
5 checks passed
WengeLiu101 pushed a commit to WengeLiu101/opencode2api that referenced this pull request Oct 24, 2026
TiaraBasori added a commit to TiaraBasori/opencode2api-1 that referenced this pull request Oct 25, 2026
…breaker)

Pick up origin/main (19 commits since v1.4.3):

- 2.1.1 client shape: version bump, /inference/openai|anthropic family
  routes, max_completion_tokens 32000, strict:false tools, client key
  order, no HTML escaping, runtime-owned Accept/Content-Length (jasonxu114514#141-jasonxu114514#143)
- anonymous-lane abuse handling: IP-block detection, per-exit block TTL,
  circuit breaker (models.anonymous_backoff), max_anonymous_exits cap,
  deterministic 4xx stops the walk instead of replaying every exit
- placeholder key dropping, probe failure classification (jasonxu114514#111),
  WebUI Cache-Control (jasonxu114514#112), reasoning disable preserved end to end
  (jasonxu114514#150), Italian README/WebUI

Conflict resolutions:
- internal/config/config.go, README.md, README.zh-CN.md: kept both sides —
  the alias fields (aliases/strip_free_suffix) and the new
  anonymous_backoff block sit side by side in ModelsConfig and the README
  tables.

Local adaptation for this deployment's #pool exit (not upstream):
- a #pool transport dials a fresh upstream address on every attempt, so an
  IP-scoped abuse block cannot be parked on the transport: blocked() and
  markBlocked() ignore pool transports and the anonymous walk keeps
  rotating instead of freezing every exit behind one flagged address.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants