fix(storage): close HTTP2 response bodies to prevent flow-control leaks#14324
Merged
krishnamd-jkp merged 3 commits intogoogleapis:mainfrom Apr 6, 2026
Conversation
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>
Contributor
There was a problem hiding this comment.
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.
cpriti-os
reviewed
Apr 2, 2026
cpriti-os
approved these changes
Apr 3, 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.
Fixes an issue where HTTP2 stream connections might exhaust flow-control quota and cause INTERNAL_ERROR in long-lived connections.
httpReader.Readto properly close the previous stream body before reopening it.parseReadResponseto ensure response bodies aren't leaked when an error is returned during header parsing.io.CopyN) orX-Goog-Generationheader parsing fails inreaderReopen. These fixes apply equally to both the JSON and XML reader code paths.