Skip to content

fix: close HTTP response body and thread context in pricing API#1479

Draft
comtalyst wants to merge 1 commit intomainfrom
comtalyst/fix-pricing-body-leak
Draft

fix: close HTTP response body and thread context in pricing API#1479
comtalyst wants to merge 1 commit intomainfrom
comtalyst/fix-pricing-body-leak

Conversation

@comtalyst
Copy link
Collaborator

@comtalyst comtalyst commented Mar 5, 2026

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.Get was used instead of http.NewRequestWithContext, so the context parameter was silently ignored (_ context.Context), preventing cancellation during operator shutdown.

Fix: use http.NewRequestWithContext to propagate context, and explicitly close res.Body after reading on every path (including non-200 status).

How was this change tested?

  • go test ./pkg/providers/pricing/... passes
  • go vet ./pkg/providers/pricing/... passes

Does this change impact docs?

  • Yes, PR includes docs updates
  • Yes, issue opened: #
  • No

Release Note


@comtalyst comtalyst marked this pull request as draft March 6, 2026 06:07
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>
@comtalyst comtalyst force-pushed the comtalyst/fix-pricing-body-leak branch from 4153460 to 7017651 Compare March 8, 2026 09:26
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