fix: close HTTP response body and thread context in pricing API#1479
Draft
fix: close HTTP response body and thread context in pricing API#1479
Conversation
The pricing API pagination loop had two issues: 1. res.Body was never closed, leaking an HTTP connection and its file descriptor on every page fetch. Over dozens of pages during each 12-hour pricing update, this accumulates leaked connections. 2. http.Get was used instead of http.NewRequestWithContext, meaning the context parameter was ignored (_ context.Context). This prevented cancellation during operator shutdown, potentially blocking the goroutine indefinitely. Fix: use http.NewRequestWithContext to propagate the context, and explicitly close res.Body after reading (not defer, since we're in a loop). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
4153460 to
7017651
Compare
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 #
Description
The pricing API pagination loop never closed
res.Body, leaking an HTTP connection per page on every 12-hour pricing update cycle.http.Getwas used instead ofhttp.NewRequestWithContext, so the context parameter was silently ignored (_ context.Context), preventing cancellation during operator shutdown.Fix: use
http.NewRequestWithContextto propagate context, and explicitly closeres.Bodyafter reading on every path (including non-200 status).How was this change tested?
go test ./pkg/providers/pricing/...passesgo vet ./pkg/providers/pricing/...passesDoes this change impact docs?
Release Note