Skip to content

proxy: return after writing max-retry-exhausted error - #454

Open
ZayanKhan-12 wants to merge 1 commit into
teslamotors:mainfrom
ZayanKhan-12:proxy-max-retry-return
Open

proxy: return after writing max-retry-exhausted error#454
ZayanKhan-12 wants to merge 1 commit into
teslamotors:mainfrom
ZayanKhan-12:proxy-max-retry-return

Conversation

@ZayanKhan-12

Copy link
Copy Markdown
Contributor

Problem

In forwardRequest's retry loop (pkg/proxy/proxy.go), when attempts reaches MaxAttempts the proxy writes a 502 max retry exhausted response — but does not return:

attempts++
if attempts == MaxAttempts {
    writeJSONError(w, http.StatusBadGateway, protocol.NewError("max retry exhausted", false, false))
}

log.Debug("Retrying transmission after error...")

Two consequences:

  1. After telling the client it gave up, the loop sleeps 1s and retries anyway.
  2. Because the guard is == rather than >=, once attempts passes MaxAttempts it can never fire again — so the loop keeps retrying until the request context expires, at which point writeJSONError(w, http.StatusGatewayTimeout, ...) writes a second response on top of the 502 already sent (http: superfluous response.WriteHeader call).

Fix

Add return after the error is written, matching every other error path in the loop.

go build ./..., go vet ./pkg/proxy/, and go test ./pkg/proxy/ pass.

🤖 Generated with Claude Code

forwardRequest wrote the 502 "max retry exhausted" response when
attempts reached MaxAttempts, but did not return. The loop then slept
and retried anyway, and because the guard checks attempts ==
MaxAttempts rather than >=, it could never fire again: the loop kept
retrying until the request context expired, at which point it wrote a
second error response (504) on top of the 502 already sent, triggering
a superfluous WriteHeader call.

Every other error path in the loop returns after writeJSONError; this
one now does too.

Co-Authored-By: Claude Fable 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