Skip to content

fix(storage): close HTTP2 response bodies to prevent flow-control leaks#14324

Merged
krishnamd-jkp merged 3 commits intogoogleapis:mainfrom
krishnamd-jkp:fix-storage-http2-leaks-14934639463026262210
Apr 6, 2026
Merged

fix(storage): close HTTP2 response bodies to prevent flow-control leaks#14324
krishnamd-jkp merged 3 commits intogoogleapis:mainfrom
krishnamd-jkp:fix-storage-http2-leaks-14934639463026262210

Conversation

@krishnamd-jkp
Copy link
Copy Markdown
Contributor

Fixes an issue where HTTP2 stream connections might exhaust flow-control quota and cause INTERNAL_ERROR in long-lived connections.

  • Modifies httpReader.Read to properly close the previous stream body before reopening it.
  • Adds a defer block in parseReadResponse to ensure response bodies aren't leaked when an error is returned during header parsing.
  • Ensures bodies are closed when stream discarding (io.CopyN) or X-Goog-Generation header parsing fails in readerReopen. These fixes apply equally to both the JSON and XML reader code paths.

Fixes an issue where HTTP2 stream connections might exhaust flow-control quota and cause INTERNAL_ERROR in long-lived connections.

- Modifies `httpReader.Read` to properly close the previous stream body before reopening it.
- Adds a defer block in `parseReadResponse` to ensure response bodies aren't leaked when an error is returned during header parsing.
- Ensures bodies are closed when stream discarding (`io.CopyN`) or `X-Goog-Generation` header parsing fails in `readerReopen`.
These fixes apply equally to both the JSON and XML reader code paths.

Co-authored-by: krishnamd-jkp <230955344+krishnamd-jkp@users.noreply.github.com>
@krishnamd-jkp krishnamd-jkp requested review from a team as code owners April 1, 2026 16:51
@product-auto-label product-auto-label Bot added the api: storage Issues related to the Cloud Storage API. label Apr 1, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request improves resource management in storage/http_client.go by ensuring http.Response.Body is consistently closed during error conditions and before retrying read operations. Key changes include moving the body closure before reopening connections in the Read method and implementing a deferred closure in parseReadResponse using named return parameters. Feedback suggests enhancing error context in parseReadResponse by wrapping the strconv.ParseInt error when handling invalid Content-Range headers.

Comment thread storage/http_client.go Outdated
Comment thread storage/http_client.go Outdated
@krishnamd-jkp krishnamd-jkp merged commit b6bcfe8 into googleapis:main Apr 6, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: storage Issues related to the Cloud Storage API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants