Skip to content

config: close request bodies when transport setup fails - #1041

Open
ViktorBystrov72 wants to merge 1 commit into
prometheus:mainfrom
ViktorBystrov72:fix/close-request-bodies-on-config-errors
Open

ViktorBystrov72 wants to merge 1 commit into
prometheus:mainfrom
ViktorBystrov72:fix/close-request-bodies-on-config-errors

Conversation

@ViktorBystrov72

Copy link
Copy Markdown

The HTTP transport wrappers return early when they cannot read credentials or header files, load TLS material, or construct a replacement transport. Those paths currently leave the request body open, contrary to the RoundTripper contract, which also requires closing it on errors. A body backed by a file or stream can therefore retain its resources after the request fails.

Close the body on errors that occur before delegating to the next transport. The regression tests cover authorization, both basic-auth credentials, file-backed headers, OAuth2 credentials and token TLS configuration, and three TLS reload failures. All nine cases fail on the parent implementation. Requests without a body are also covered.

Validation: make test GOOPTS=-race passed with Go 1.27.3 and golangci-lint 2.14.0, including root tests, lint, license, and module-tidy checks. git diff --check passed.

@roidelapluie @gotjosh

@ViktorBystrov72
ViktorBystrov72 force-pushed the fix/close-request-bodies-on-config-errors branch 3 times, most recently from 0a50acb to f3616db Compare November 13, 2026 08:39
Signed-off-by: Виктор Быстров <anatema@bk.ru>
@ViktorBystrov72
ViktorBystrov72 force-pushed the fix/close-request-bodies-on-config-errors branch from f3616db to 1061c0e Compare November 14, 2026 05:45
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