Repository navigation
fix(client): close the final failed response in errorHandler - #585
Closed
vuanhphung wants to merge 4 commits into
Closed
vuanhphung wants to merge 4 commits into
vuanhphung wants to merge 4 commits into
Conversation
retryablehttp passes the last response of a failed request to the custom ErrorHandler and leaves closing it to the handler. errorHandler returned it, still open, together with the error, and net/http discards a response returned with an error, so nothing closed it. Every failed request through RetryableClient leaked its response body and connection until the 900s client timeout: retries exhausted on 429/503, and also every non-200 that isn't retried (401, 500 on ExecuteStatement, telemetry and feature-flag errors). net/http also logged "RoundTripper returned a response & error; ignoring response" each time. Close the body in errorHandler and return a nil response, as retryablehttp's default handler does. The error is unchanged, and the transport still drains a small body after Close, so the connection stays reusable. Signed-off-by: Vu Anh Phung <[email protected]> Co-authored-by: Isaac <[email protected]>
Connect to the warehouse with an invalid token (403 on OpenSession) through a body-counting transport, and assert every response body was closed. Fails on the previous errorHandler with 3 of 3 left open. Signed-off-by: Vu Anh Phung <[email protected]> Co-authored-by: Isaac <[email protected]>
Address adversarial-review round 1: - Test errorHandler directly: it returns no response, closes the body, and keeps the reason-phrase / Thrift error header and status text. - Cover a redirect-limit failure, where net/http hands errorHandler an already closed body. - Give the 429 case a body (so the connection check can fail) and keep an empty-body case; drop a nil-response assertion that couldn't fail. - Make the std-log capture race-safe and print it on failure. - Correct the telemetry exporter comment: with SkipTransientRetries a 429/503 arrives as a normal response with a nil error. - Changelog: the leak held an HTTP/1.1 connection or HTTP/2 stream until the request context ended or the client timeout fired. Signed-off-by: Vu Anh Phung <[email protected]> Co-authored-by: Isaac <[email protected]>
vuanhphung
marked this pull request as ready for review
November 20, 2026 06:06
There was a problem hiding this comment.
🔀 Cross-reviewed: two independent reviews (Claude Opus 5.5 · GPT-6.1 Sol), checked by a judge model (Claude Sonnet 5.5).
Verdict: 1 Low
Looks good, with 1 low concern. errorHandler now closes the body and returns nil, which matches retryablehttp's default handler. Callers only see the error through StandardClient, and the error content is unchanged.
Add TestE2ERejectedRequestClosesResponse to the nightly Thrift E2E -run allowlist so the live 403 check runs in CI. Signed-off-by: Vu Anh Phung <[email protected]> Co-authored-by: Isaac <[email protected]>
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a request through the driver's retrying HTTP client fails, go-retryablehttp passes the last response to our custom
errorHandlerand leaves closing it to the handler (its default handler drains and closes;client.go:807-815@v0.7.7).errorHandlerreturned that response, still open, along with the error. net/http discards a response that a RoundTripper returns with an error (client.gosend: "RoundTripper returned a response & error; ignoring response"), so nothing ever closed it.Exhausted retries are only one way to get there.
RetryPolicyreturns(false, checkErr)for any non-200 response it doesn't retry, so a 401 or 403, a 5xx onExecuteStatement, and telemetry or feature-flag errors also reacherrorHandler. Other Thrift RPCs get there after retries run out. The leaked body kept its HTTP/1.1 connection, which counted towardMaxConnsPerHost(100), or its HTTP/2 stream open. It stayed open until the request context ended or the 900sClientTimeoutfired. Empty bodies leaked only the body. net/http also printed the line above to stderr for every failure.Fix
errorHandlerclosesresp.Bodyand returns a nil response, as retryablehttp's default handler does. The error is unchanged: reason phrase, Thrift error header, status text and 429 rate-limit category. Retry behavior is unchanged too.There is no explicit drain. Since Go 1.27 (this module requires 1.27.3),
http.Transportdrains up to 256 KiB or 50 ms after an earlyCloseand then reuses the connection. SoClosedoesn't wait on the body before the error is reported, and the connection stays reusable.Verification
mainRetryableClient): 503 and 429 exhausted, 500 and 401 not retried, 503 with a 64 KiB body, ThriftExecuteStatement503TestErrorHandlerClosesResponsetestserrorHandlerdirectly.TestRetryableClientClosesFailedResponseandTestThriftExecuteClosesRetryExhaustedResponserun the real client stack, plus an empty-body case.TestRetryableClientRedirectLimitErrorcovers the already-closed body net/http passes on a redirect-limit error. The liveTestE2ERejectedRequestClosesResponsecovers a real 403. All but the redirect test fail onmain.make test,make lint(0 issues),-raceoninternal/client,telemetry,internal/featureflagsand the root package, the kernel-tagged tests (GOTOOLCHAIN=go1.27.3), live Thrift e2e, and live kernel e2e.main:TestKernelCloudFetchDisabledPreservesUnsupportedServerErrorand the liveTestKernelE2EErrorTelemetryCategory.errorHandlerruns only after a request has failed, so the success path is unchanged.Also corrects a telemetry exporter comment. With
SkipTransientRetries, a 429/503 arrives as a normal response with a nil error, not as a response plus an error.Cross-driver state
DatabricksRetryHandlerException(DatabricksHttpRetryHandler.java:98@97dac8d), and Apache HttpClient 4.5.14ProtocolExeccloses the response (library behavior, checked in its sources). Other statuses close via try-with-resources (DatabricksHttpTTransport.java:128).finally: self._transport.close()runsdrain_conn()andrelease_conn()(thrift_backend.py:533,thrift_http_client.py:154@087b2bf). urllib3 drains the last response when retries run out.errorHandlercloses the final response.THTTPException(ThriftHttpConnection.ts:183-184@7667e36). After retries,HttpRetryPolicythrows aRetryErrorholding the response (HttpRetryPolicy.ts:127,135). Neither path consumes or destroys the body. Separate follow-up.response.text()consumes the body on terminal failures (src/client/http.rs:976,1008@8877579).Adversarial review: converged in 1 round with no high findings. All 5 low findings were fixed: wording, cross-driver citations, a direct
errorHandlertest, race-safe log capture, and a stale telemetry comment.This pull request and its description were written by Isaac.