Skip to content

feat(rpc): handle rate limiting and Retry-After - #141

Merged
Ayinkx01 merged 1 commit into
StellarFoundry:mainfrom
olaams-tech:feat/rpc-rate-limit-retry-after
Oct 28, 2026
Merged

Ayinkx01 merged 1 commit into
StellarFoundry:mainfrom
olaams-tech:feat/rpc-rate-limit-retry-after

Conversation

@olaams-tech

Copy link
Copy Markdown
Contributor

Summary

Adds distinct handling for RPC rate limits.

  • HttpTransport detects HTTP 429 Too Many Requests and returns a typed DevkitError::RateLimited carrying the numeric Retry-After delay instead of a generic I/O error.
  • Client retries rate-limit responses only while the requested delay fits inside a configurable cumulative cap (RetryPolicy::max_rate_limit_wait, 60s by default). A missing or non-numeric Retry-After falls back to a bounded 1s backoff.
  • If the requested wait would exceed the cap, the client returns a clear rate-limit error immediately and never sleeps past the cap.
  • The CLI maps the new error category to rate_limited; the JSON error envelope and exit code are unchanged.

Tests

  • Mocked 429 responses assert retry-then-success and retry exhaustion.
  • A local HTTP server test exercises the real HttpTransport 429 path and Retry-After parsing.
  • Cap-exceeded behavior is tested without real waiting.
  • Retry-After parsing covers seconds, whitespace, and unsupported HTTP-date values.

Verification

cargo fmt --all -- --check
cargo clippy --all-targets --all-features -- -D warnings
cargo test --all

All pass.

Closes #45

Detect HTTP 429 responses in HttpTransport, carry a numeric Retry-After delay on a typed DevkitError::RateLimited, and retry within a configurable cumulative cap (60s by default). Requests that would exceed the cap fail immediately with a clear error instead of sleeping unboundedly. Add mocked and local-server tests plus documentation.

Closes StellarFoundry#45
@olaams-tech
olaams-tech requested a review from Ayinkx01 as a code owner October 28, 2026 15:03
@Ayinkx01
Ayinkx01 merged commit 7a898c2 into StellarFoundry:main Oct 28, 2026
6 checks passed
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.

feat(rpc): handle rate limiting and Retry-After

3 participants