Skip to content

fix(aws/recommendations): protect RateLimiter against concurrent access (closes #271)#865

Open
cristim wants to merge 1 commit into
feat/multicloud-web-frontendfrom
fix/271-wave18
Open

fix(aws/recommendations): protect RateLimiter against concurrent access (closes #271)#865
cristim wants to merge 1 commit into
feat/multicloud-web-frontendfrom
fix/271-wave18

Conversation

@cristim
Copy link
Copy Markdown
Member

@cristim cristim commented May 30, 2026

Summary

  • RateLimiter was stored as a single *RateLimiter field on Client and shared across all 6 concurrent goroutines spawned by GetAllRecommendations. Reset, ShouldRetry, and GetRetryCount all mutate retryCount without synchronisation, causing data races detected by go test -race.
  • Replaced the shared rateLimiter *RateLimiter field with a newRateLimiter func() *RateLimiter factory. Each of the four fetch*WithRetry / fetch*Page functions now calls rl := c.newRateLimiter() at entry, giving every call site its own independent retry budget (correct: these are not shared throughput limiters).
  • Guarded callCount and riCalls mutations in mockCostExplorerAPI with a sync.Mutex - they were also racing when GetAllRecommendations called the mock from multiple goroutines.

Test plan

  • go test -race github.com/LeanerCloud/CUDly/providers/aws/recommendations/... passes (280 tests, no data race report)

🤖 Generated with claude-flow

)

RateLimiter was a single *RateLimiter field on Client, shared across the
6 concurrent goroutines that GetAllRecommendations fans out via errgroup.
Reset/ShouldRetry/GetRetryCount all mutate retryCount without a lock,
triggering data races under go test -race.

Per feedback_rate_limiter_per_call.md: each goroutine needs its own
independent retry budget (not shared throughput), so per-call
instantiation is correct over adding a mutex.

Replace rateLimiter *RateLimiter with newRateLimiter func() *RateLimiter.
Each fetch*WithRetry / fetch*Page function calls rl := c.newRateLimiter()
at entry. Tests inject a factory returning a faster limiter for speed.

Also fix mockCostExplorerAPI: callCount and riCalls were mutated by
concurrent goroutines without synchronisation. Add sync.Mutex guard.
@cristim cristim added triaged Item has been triaged priority/p3 Polish / idea / may never ship severity/low Minor harm urgency/eventually No deadline impact/internal Team-internal only effort/s Hours type/bug Defect labels May 30, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 30, 2026

Warning

Review limit reached

@cristim, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 24 minutes and 17 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4f182185-9292-47d3-841d-81f9ec1e5f34

📥 Commits

Reviewing files that changed from the base of the PR and between 4956d66 and cb84103.

📒 Files selected for processing (5)
  • providers/aws/recommendations/client.go
  • providers/aws/recommendations/client_test.go
  • providers/aws/recommendations/coverage.go
  • providers/aws/recommendations/parser_sp.go
  • providers/aws/recommendations/utilization.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/271-wave18

Comment @coderabbitai help to get the list of available commands and usage tips.

@cristim
Copy link
Copy Markdown
Member Author

cristim commented May 30, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 30, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

Labels

effort/s Hours impact/internal Team-internal only priority/p3 Polish / idea / may never ship severity/low Minor harm triaged Item has been triaged type/bug Defect urgency/eventually No deadline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant