Skip to content

fix(proxy): do not probe a proxy after a client-canceled request - #185

Open
gerarecipe wants to merge 1 commit into
jasonxu114514:mainfrom
gerarecipe:canceled-probe
Open

gerarecipe wants to merge 1 commit into
jasonxu114514:mainfrom
gerarecipe:canceled-probe

Conversation

@gerarecipe

Copy link
Copy Markdown

Problem

When a client abandons a request (closes the connection, cancels a stream before the first byte), the attempt ends with context.Canceled and no HTTP response. syncProxyResult treats that like any other upstream request error and starts a confirming proxy health check.

That check runs on context.WithoutCancel(ctx) by design, so it really goes out through the proxy. Since #111, any failed check marks the proxy unavailable and moves its keys. A client hanging up therefore costs an extra request through the exit, and if that check happens to fail for an unrelated reason the proxy is evicted and its keys rebound — although the proxy never failed.

Root cause

checkClaimedProxy already exempts context.Canceled ("a caller that went away says nothing about the route"), but syncProxyResult decides to start the check before that exemption can apply, and the check itself no longer carries the cancellation.

Change

In syncProxyResult, return early for errors.Is(err, context.Canceled) instead of calling verifyProxyAfterError. Nothing else moves: real transport failures (isProxyFailure) are handled before this branch, and other request errors still trigger the confirming check exactly as #111 intends. A wrapped context.Canceled is covered by errors.Is.

Verification

  • gofmt -l ., go vet ./..., Linux and Windows builds: clean.
  • The repository carries no _test.go files, so none is added. A throwaway test (not committed) called syncProxyResult with context.Canceled and with a wrapped context.Canceled: no check was started and the proxy stayed healthy; the same test fails on current main (a check is started). Happy to add it if you want tests in the tree.

🤖 Generated with Claude Code

A request the client abandons ends with context.Canceled and no HTTP
response. syncProxyResult still started a confirming health check for it,
on a context without cancellation, and since jasonxu114514#111 any failed check marks
the proxy unavailable and moves its keys. A canceled request says nothing
about the proxy; checkClaimedProxy already exempts context.Canceled for
the same reason. Skip the confirming probe for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant