fix: close demand probe response bodies#1057
Merged
jranson merged 1 commit intoJul 13, 2026
Merged
Conversation
jranson
requested changes
Jul 13, 2026
Member
There was a problem hiding this comment.
@houyuwushang this is a valid defect, thanks for finding! However, the fix is incomplete. It is possible (and likely) for an error response to include a body, but this fix only closes the body of successful responses since a non-nil err would cause demandProbe to exit prior to the deferred body close. So error response bodies would remain unclosed. A complete fix would be to do this immediately after the t.httpClient.Do call on L317 and before the err nil check on L319:
if resp != nil && resp.Body != nil {
defer resp.Body.Close()
}
Signed-off-by: houyuwushang <liuluoqianqiu@outlook.com>
6f0e20f to
eeb2d89
Compare
Contributor
Author
|
Moved the body close immediately after |
jranson
approved these changes
Jul 13, 2026
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.
Description
The on-demand healthcheck path copied an upstream response body to the caller but never closed it. That left response-body resources owned by the transport open after each demand probe and could prevent normal connection cleanup.
This closes a non-nil upstream body after forwarding completes. The regression test uses a tracking
ReadCloserto verify both that the body is closed and that its content is still returned to the caller.Validation:
go test ./pkg/backends/healthcheck/... ./pkg/proxy/handlers/health/... -count=1go test -race ./pkg/backends/healthcheck -run '^(TestDemandProbe|TestDemandProbeClosesUpstreamBody)$' -count=20go tool golangci-lint run --timeout 5m ./pkg/backends/healthcheck/...go test -run '^$' ./...Reviewer: @jranson
Type of Change
AI Disclosure