fix(aws/recommendations): protect RateLimiter against concurrent access (closes #271)#865
fix(aws/recommendations): protect RateLimiter against concurrent access (closes #271)#865cristim wants to merge 1 commit into
Conversation
) 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.
|
Warning Review limit reached
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 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Summary
RateLimiterwas stored as a single*RateLimiterfield onClientand shared across all 6 concurrent goroutines spawned byGetAllRecommendations.Reset,ShouldRetry, andGetRetryCountall mutateretryCountwithout synchronisation, causing data races detected bygo test -race.rateLimiter *RateLimiterfield with anewRateLimiter func() *RateLimiterfactory. Each of the fourfetch*WithRetry/fetch*Pagefunctions now callsrl := c.newRateLimiter()at entry, giving every call site its own independent retry budget (correct: these are not shared throughput limiters).callCountandriCallsmutations inmockCostExplorerAPIwith async.Mutex- they were also racing whenGetAllRecommendationscalled 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