Skip to content

squid: rgw: add accurate Retry-After header to rate-limit responses - #20

Merged
uw-sc merged 2 commits into
squid-19.2.6-cobaltcore-storagefrom
backport/585-2-fix
Oct 6, 2026
Merged

uw-sc merged 2 commits into
squid-19.2.6-cobaltcore-storagefrom
backport/585-2-fix

Conversation

@s0nea

@s0nea s0nea commented Oct 1, 2026 •

Copy link
Copy Markdown

When RGW rejects an S3 request with -ERR_RATE_LIMITED, return an HTTP Retry-After header that tells the client how many seconds to wait before retrying. The value is computed from the current token-bucket deficit and replenishment rate, so a polite client that honors the header will retry right around when its tokens recover.

The delay is threaded out of the rate limiter through req_state and onto the response in abort_early(). The rate-limit check now returns int64_t seconds (0 = allowed) instead of bool, with a 1-second floor on the rejected path.

The seconds-to-recover calculation is factored into a small static helper RateLimiterEntry::compute_delay(limit, needed, interval) so it can be unit-tested directly. Each dimension (ops, bytes) calls it independently and the caller takes the max, leaving room for additional limit dimensions in the future.

The user-facing documentation is updated to describe the new header and to suggest proxy-layer remapping for operators who need 429 instead of the existing 503.

Tracker: https://tracker.ceph.com/issues/64083
Tracker: https://tracker.ceph.com/issues/67655

(cherry picked from commit 3dae903)

Closes cobaltcore-dev/cloud-storage#585

Backport file

  • release-management/backports/<uuid>.md added (or updated) by this PR
  • id in frontmatter matches the filename stem
  • provenance.upstream_prs set (or provenance.type: other with an other: block)

Stage-B risk (filled per release-management/backports/RISK-RUBRIC.md)

  • blast — cosmetic / availability / data-loss
  • conflict — clean / trivial / substantive
  • coverage — strong / partial / weak
  • Risk-notes paragraph in the prose section (required for high band)

Merge

Land this via just merge-backport PR=<N> — do not click the green merge button.
The just recipe constructs the merge commit's Backport-Id trailer.

@s0nea
s0nea force-pushed the backport/585-2-fix branch from dd2db04 to 46d50c2 Compare October 1, 2026 14:26
When RGW rejects an S3 request with -ERR_RATE_LIMITED, return an HTTP
Retry-After header that tells the client how many seconds to wait before
retrying. The value is computed from the current token-bucket deficit and
replenishment rate, so a polite client that honors the header will retry
right around when its tokens recover.

The delay is threaded out of the rate limiter through req_state and onto
the response in abort_early(). The rate-limit check now returns int64_t
seconds (0 = allowed) instead of bool, with a 1-second floor on the
rejected path.

The seconds-to-recover calculation is factored into a small static helper
RateLimiterEntry::compute_delay(limit, needed, interval) so it can be
unit-tested directly. Each dimension (ops, bytes) calls it independently
and the caller takes the max, leaving room for additional limit
dimensions in the future.

The user-facing documentation is updated to describe the new header and
to suggest proxy-layer remapping for operators who need 429 instead of
the existing 503.

Tracker: https://tracker.ceph.com/issues/64083
Tracker: https://tracker.ceph.com/issues/67655
Signed-off-by: Lumir Sliva <[email protected]>
(cherry picked from commit 3dae903)

3dae903 has been cherry-picked without its parents: 91e9f00 "rgw: ops
large budget caused by rate limiter was enabled and max_ops set to 0"
and dae572d "rgw: add rate limit for LIST & DELETE ops"

Conflicts:

src/rgw/rgw_process.cc
- rate_limit(): bool -> int64_t and remove s->info.request_params from
   should_rate_limit() (added by dae572d).

src/rgw/rgw_ratelimit.h
- should_rate_limit_list() and should_rate_limit_delete(): remove them
  (added by dae572d).
- should_rate_limit_read(): remove decrement in `if (read_ops() > 0)`
  (91e9f00's fix). But keep return type int64_t.
- should_rate_limit_write(): remove decrement in `if (write_ops() > 0)`
  (91e9f00's fix). But keep return type int64_t.
- RateLimiterEntry::should_rate_limit(): signature switches
  `bool is_read` -> `OpType op_type` (dae572d). Kept the bool, changed
  only the return type to int64_t.
- RateLimiterEntry::should_rate_limit(): keep the direct
  should_rate_limit_write() call instead of switch over OpType.
- RateLimiter::should_rate_limit() signature: remove the  added
  `const std::string& resource` parameter the
  `ldpp_dout(this, 21) << ... std::quoted(key) ...` trace (dae572d).

Not a conflict but adapted manually: `main` reads the interval from
g_ceph_context->_conf->rgw_ratelimit_interval, an option added by
dae572d. Replace it with a new constant with the default value of 60s,
RateLimiterEntry::ratelimit_interval_seconds = 60.

src/test/rgw/test_rgw_ratelimit.cc
- Change bool success / EXPECT_EQ(true|false, success) to
  int64_t delay / EXPECT_EQ(0, delay) or EXPECT_GT(delay, 0).
- should_rate_limit(): do not apply the extra "" resource argument
  (dae572d).
- giveback_tokens(); do not apply (resource, info) arguments to
  giveback_tokens() (dae572d).
- OpType::Read/Write in the RGWRateLimitEntry tests stay as bool.
@s0nea
s0nea force-pushed the backport/585-2-fix branch from 46d50c2 to e90dca8 Compare October 1, 2026 15:54
@s0nea s0nea changed the title rgw: add accurate Retry-After header to rate-limit responses squid: rgw: add accurate Retry-After header to rate-limit responses Oct 2, 2026
@s0nea
s0nea force-pushed the backport/585-2-fix branch 2 times, most recently from 6481652 to 1dce0d8 Compare October 6, 2026 08:02
Signed-off-by: Tatjana Dehler <[email protected]>
@s0nea
s0nea force-pushed the backport/585-2-fix branch from 1dce0d8 to 6dc3992 Compare October 6, 2026 09:27
@s0nea

s0nea commented Oct 6, 2026

Copy link
Copy Markdown
Author

Test Ceph CobaltCore Unit Tests / Run Ceph Unit Tests (pull_request)

Run actions/checkout@v4
Syncing repository: cobaltcore-dev/ceph
Getting Git version info
Deleting the contents of '/home/cloud-user/actions-runner/_work/ceph/ceph'
The repository will be downloaded using the GitHub REST API
To create a local Git repository instead, add Git 2.18 or higher to the PATH
Error: Input 'submodules' not supported when falling back to download using the GitHub REST API. To create a local Git repository instead, add Git 2.18 or higher to the PATH.

@uw-sc
uw-sc merged commit 99f2d55 into squid-19.2.6-cobaltcore-storage Oct 6, 2026
2 of 4 checks passed
uw-sc added a commit that referenced this pull request Oct 14, 2026
Backport-Id: 01a0fca1-b10e-7c21-97cc-f83d8a61565c
Backport-PR: #20
Upstream-PRs: ceph#68210
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.

3 participants