Skip to content

fix: disconnect low-level response on construction failure to prevent connection leak - #2178

Open
insaf021 wants to merge 1 commit into
googleapis:mainfrom
insaf021:fix/disconnect-on-response-construction-failure
Open

fix: disconnect low-level response on construction failure to prevent connection leak#2178
insaf021 wants to merge 1 commit into
googleapis:mainfrom
insaf021:fix/disconnect-on-response-construction-failure

Conversation

@insaf021

Copy link
Copy Markdown

Summary
HttpResponse construction can throw a RuntimeException. The existing finally block in
HttpRequest.execute() closes the content stream in that case but never calls
LowLevelHttpResponse.disconnect(), leaving the socket open.

Changes

  • HttpRequest.java: call disconnect() in the finally block when response construction
    fails; added null-guard and isolated getContent() failures so they don't suppress
    the disconnect() call.
  • HttpRequestTest.java: added testExecute_disconnectOnResponseConstructionFailure.

Notes
Pre-existing bug, unrelated to the security hardening work (redirect credential stripping,
CRLF validation, XXE hardening) — those are separate PRs.

  • Opened an issue before writing code
  • Tests and linter pass
  • Code coverage does not decrease
  • Docs updated

Fixes #2177 ☕️

@insaf021
insaf021 requested a review from a team as a code owner July 30, 2026 10:05
@product-auto-label product-auto-label Bot added the size: s Pull request size is small. label Jul 30, 2026
@insaf021 insaf021 changed the title fix: disconnect low-level response on construction failure to prevent… fix: disconnect low-level response on construction failure to prevent connection leak Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: s Pull request size is small.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Core: LowLevelHttpResponse not disconnected when HttpResponse construction throws RuntimeException

1 participant