Skip to content

fix(relay): tunnel cleanup keeps up with new idle tunnels - #26135

Merged
juliusmarminge merged 1 commit into
mainfrom
relay/reaper-throughput
Oct 28, 2026
Merged

juliusmarminge merged 1 commit into
mainfrom
relay/reaper-throughput

Conversation

@juliusmarminge

Copy link
Copy Markdown
Member

The managed tunnel reaper stopped shrinking the idle-tunnel backlog. Since Oct 22 the down count has swung between 5.5k and 8.5k every day, and its daily peak keeps creeping up. 93% of sweeps hit the 100-deletes-per-sweep cap. That caps the reaper at 1,200 deletes an hour, which is about the rate new idle tunnels arrive.

This change allows up to 250 deletes per sweep and runs 8 at a time instead of 4. I took the sizing from production traces:

  • Time budget: a delete takes about 2.8s, so at 8 at a time a sweep fits about 230 into its 90s budget. The existing deadline stops a sweep cleanly if it runs long.
  • Hyperdrive: about 1.85s of each delete is spent inside a row-locked transaction. Eight deletes at a time therefore hold about 5 of the 40 Hyperdrive origin connections, which request handlers also use. Request handlers average 12 queries in flight, and 17–20 in the busiest minutes. The code comment still said the limit was 20; it now says 40.
  • Cloudflare API: the change adds at most about 300 calls per 5 minutes. Relay peaks at about 2,100 against the account's 20,000 limit, and there were no 429s in the last 3 days. The ops doc now records that limit.

The two rotation tests used 100 as the limit; they now read the constant.

Once this is deployed, the backlog should drain to about 1k within a day. What remains is legacy tunnels inside their 7-day grace period, plus each sweep's new arrivals.

🤖 Generated with Claude Code (Claude Opus 5.5)

The reaper hit its 100-deletes-per-sweep cap on 93% of sweeps, so new
idle tunnels arrived as fast as it removed them and the backlog stopped
shrinking at 5.5k-8.5k. Allow 250 deletes per sweep at concurrency 8.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Oct 27, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at bef2874

Macroscope's review found this PR approvable — Increases idle-tunnel cleanup throughput while retaining existing deletion eligibility, ownership checks, time limits, and rate-limit safeguards. Product behavior and retention thresholds remain unchanged.

You can add or adjust custom eligibility rules. Learn more.

@coderabbitai

coderabbitai Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 5808469 and bef2874.

Files selected for processing: 3
  • docs/operations/relay-observability.md
  • infra/relay/src/environments/ManagedEndpointReaper.test.ts
  • infra/relay/src/environments/ManagedEndpointReaper.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review.

Walkthrough

The operations guidance now states Cloudflare’s October 2026 account rate limit and peak usage. The managed endpoint reaper increases its attempt limit and delete concurrency, and its tests use the configured attempt limit.

Changes: Cloudflare rate-limit guidance

Layer / File(s) Summary
Update rate-limit figures
docs/operations/relay-observability.md
The alert guidance states an account limit of 20,000 calls per 5 minutes and peak usage of about 2,100.

Managed endpoint reaper

Layer / File(s) Summary
Update sweep limits and test thresholds
infra/relay/src/environments/ManagedEndpointReaper.ts, infra/relay/src/environments/ManagedEndpointReaper.test.ts
The attempt limit increases from 100 to 250, and delete concurrency increases from 4 to 8. The deletion-order tests use the configured attempt limit for candidate counts and assertions.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • pingdotgg/t3code#23683: Updates the same reaper cleanup path to pass recovery state and generation to ManagedEndpointProvider.release.

Suggested reviewers: maria-rcks, t3dotgg

Merge Risk: Minimal · up to bef28

No demonstrated issue prevents merging the sweep-limit and guidance updates after normal checks.

Pre-merge checks: Passed 3 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Description check Warning The description explains the backlog problem and the concurrency and sweep-limit changes. It does not provide the required Scope and approval section, and it does not clearly document focused verifica… Add explicit Problem, Change, Scope and approval, and Verification sections. Provide the linked issue or maintainer approval, or explain why this focused fix is exempt. List the focused tests or manual checks that were run and their observe…
Passed Passed checks: 3 passed
Check name Status Explanation
Title check Passed The title clearly and concisely identifies the relay tunnel cleanup fix. It matches the main change in the pull request.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description explains the backlog problem and the concurrency and sweep-limit changes. It does not provide the required Scope and approval section, and it does not clearly document focused verification tests or their observed results.

Resolution

Add explicit Problem, Change, Scope and approval, and Verification sections. Provide the linked issue or maintainer approval, or explain why this focused fix is exempt. List the focused tests or manual checks that were run and their observed results, including anything not checked.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@juliusmarminge
juliusmarminge merged commit 9638e17 into main Oct 28, 2026
29 checks passed
@juliusmarminge
juliusmarminge deleted the relay/reaper-throughput branch October 28, 2026 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS 0-9 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant