Skip to content

fix(azure/gcp/aws): add ctx.Err() guards and page-cap to all pagination loops #691

Description

@cristim

Summary

Pagination loops across the Azure and GCP provider clients are missing ctx.Err() checks between pages and have no maximum-page budget. This is the same failure shape fixed in PR #690 for the 7 AWS services -- discovered during the survey requested in #688.

All affected loops are unbounded and lack an early-exit on context cancellation. When running under a Lambda deadline these loops can eat the entire remaining budget before the SDK surfaces the cancellation error.

Affected locations

Azure -- for pager.More() { pager.NextPage(ctx) } without ctx.Err() check (smell #2)

  • providers/azure/services/compute/client.go:136 -- GetRecommendations
  • providers/azure/services/compute/client.go:171 -- GetExistingCommitments
  • providers/azure/services/compute/client.go:362 -- GetValidResourceTypes
  • providers/azure/services/cache/client.go:136 -- GetRecommendations
  • providers/azure/services/cache/client.go:170 -- GetExistingCommitments
  • providers/azure/services/cache/client.go:359 -- GetValidResourceTypes
  • providers/azure/services/database/client.go:138 -- GetRecommendations
  • providers/azure/services/database/client.go:172 -- GetExistingCommitments
  • providers/azure/services/cosmosdb/client.go:139 -- GetRecommendations
  • providers/azure/services/cosmosdb/client.go:173 -- GetExistingCommitments
  • providers/azure/services/cosmosdb/client.go:364 -- GetValidResourceTypes
  • providers/azure/services/search/client.go:136 -- GetRecommendations
  • providers/azure/services/search/client.go:170 -- GetExistingCommitments
  • providers/azure/services/search/client.go:358 -- GetValidResourceTypes

GCP -- iterator loops without ctx.Err() check (smell #2)

  • providers/gcp/services/computeengine/client.go:205 -- GetRecommendations iterator
  • providers/gcp/services/computeengine/client.go:247 -- GetExistingCommitments iterator
  • providers/gcp/services/computeengine/client.go:441 -- GetValidResourceTypes iterator
  • providers/gcp/services/cloudsql/client.go:163 -- GetRecommendations iterator
  • providers/gcp/services/memorystore/client.go:163 -- GetRecommendations iterator
  • providers/gcp/services/memorystore/client.go:203 -- GetExistingCommitments iterator

Minimum fix (small effort)

For each for pager.More() loop body, add at the top:

if err := ctx.Err(); err != nil {
    return nil, fmt.Errorf("context cancelled during pagination: %w", err)
}

For each GCP for { it.Next() } loop body, same guard.

Add a const maxPages = 50 (or suitable value) page budget per loop with a warning log when hit, matching the pattern from PR #690.

Context

A separate issue covers the Azure Retail Prices API NextPageLink truncation (smell #5) in the same files -- that fix is larger and touches the HTTP-level pricing helpers.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions