fix(plugin): pause every cache purge drain while Cloudflare rate-limits purges
Summary
Follow-up to #4303, found while monitoring it in prod (capgo-23.2.1). #4303 made each drain stop after a failed batch, but the /updates cache purge queue still grew: 739, then 747, then 756 due apps over 80 s. The API worker kept logging hundreds of Cloudflare 429s a minute, mostly on the second zone.
The cause is that a failed batch only requeued its own apps. Every other drain kept claiming a batch per second, up to 6,000 tags a minute per zone. Each channel or version update nudges a drain, so about 480 drains started in 90 s. All of them called the rate-limited purge API, so its quota never recovered.
- Global back-off: migration
20261201120200_updates_cache_purge_global_backoffchangesack_updates_cache_purge(..., p_success => false, ...). A failed ack now also movesupdates_cache_purge_state.last_claim_atto the end of the Retry-After window.claim_updates_cache_purgethen answersthrottledto every drain until it ends. Same function signature, and successful acks are unchanged. - Longer wait on 429: Cloudflare's purge API answers 429 without
Retry-After. A 429 now waits 30 s instead of 5 s; other failures stay at 5 s.
Failed apps are still requeued, never dropped. Once the limit clears, the next claim resumes the queue.
Test plan
- New pgTAP test
supabase/tests/99_test_updates_cache_purge_backoff.sqlchecks four things:- A failed ack requeues the app at its Retry-After.
- A failed ack moves the shared throttle.
- A second claim is
throttledwhile another app is due. - A successful ack leaves the throttle alone.
- Unit test: a 429 without
Retry-Aftergives 30 s; a 500 gives 5 s. -
bun run test:unit(679 files),typecheck:backend,lint:backend, migration order check - CI, including pgTAP against fresh Postgres
- After deploy: 429 logs drop, and
updates_cache_purge_pendingdrains.
No rendered UI changes, so there are no screenshots.
š¤ Generated with Claude Code
Summary by CodeRabbit
- Bug Fixes
- Improved cache-purge retry handling for rate-limited requests: when no valid retry delay is provided, the system waits 30 seconds before trying again. Other failed requests continue to use a 5-second default.
- Coordinated retry timing across purge requests to reduce repeated attempts during backoff periods.