fix(perps): retry candle data fetch on too-many-requests errors cp-7.72.0#28161
fix(perps): retry candle data fetch on too-many-requests errors cp-7.72.0#28161michalconsensys wants to merge 3 commits intomainfrom
Conversation
Propagate onError from CandleStreamChannel subscriptions and add retry logic in PerpsMarketDetailsView that re-fetches candle history up to 12 times with 5s delays when rate-limited, preventing empty chart states.
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
Extract useRefetchCandleDataOnError into its own hook file for testability and add post-sleep cancellation checks. Add 8 hook tests covering retry, max-retries, unmount cleanup, and case-insensitive matching. Update CandleStreamChannel tests for the new fetchMoreHistory Date.now fallback and add 4 tests for onError propagation.
The real sleep from @walletconnect/utils is already a plain setTimeout wrapper, so jest.useFakeTimers() controls it directly.
🔍 Smart E2E Test Selection⏭️ Smart E2E selection skipped - draft PR All E2E tests pre-selected. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
| }, | ||
| onError: (error: Error) => { | ||
| // Log initialization failure | ||
| onError?.(error); |
There was a problem hiding this comment.
First subscriber's onError called twice on error
Medium Severity
The connect() error handler calls onError?.(error) directly on line 284 (new code), and then the existing subscriber loop on lines 296–301 also calls subscriber.onError?.(error) for all matching subscribers — including the first subscriber whose onError is the same function reference passed to connect(). This results in the first subscriber's onError being invoked twice per error event, causing duplicate Logger.error() reports to Sentry in usePerpsLiveCandles.
Additional Locations (1)
|
|
✅ E2E Fixture Validation — Schema is up to date |
|
Closed in favour of #28176 |





Description
When the HyperLiquid API returns "too many requests" rate-limiting errors during candle data initialization, the chart would remain permanently empty with no recovery path. This PR adds retry logic so the chart self-heals after being rate-limited.
Changes:
CandleStreamChannel.ts: PropagatesonErrorcallback through theconnect→ WebSocket subscription flow so consumers can react to initialization failures. Removes the early return infetchMoreHistorywhen no cached data exists, allowing history fetches even after a failed initial load (falls back toDate.now()as the anchor timestamp).PerpsMarketDetailsView.tsx: Adds auseRefetchCandleDataOnErrorhook that detects "too many requests" errors and retriesfetchMoreHistoryup to 12 times with 5-second intervals, stopping as soon as candles are loaded.Changelog
CHANGELOG entry: Fixed an issue where the Perps chart would remain empty after being rate-limited by the data provider
Related issues
Partially resolves: #28141
Manual testing steps
Screenshots/Recordings
N/A — no UI changes, behavior-only fix.
Before
Chart stays permanently empty after a "too many requests" error.
After
Screen.Recording.2026-03-31.at.13.44.51.mov
Chart automatically retries and recovers once the rate limit lifts.
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Medium Risk
Touches the candle streaming/retry path used to render Perps charts; incorrect error propagation or retry timing could cause extra network load or continued empty charts, but scope is limited to this data flow.
Overview
Prevents the Perps chart from getting stuck empty after candle subscription initialization hits a "too many requests" rate-limit error.
CandleStreamChannelnow propagates subscriptiononErrorback to subscribers and allowsfetchHistoricalCandlesto run even when cache is empty (anchoring withDate.now()), enabling recovery after a failed initial load.PerpsMarketDetailsViewwires in a newuseRefetchCandleDataOnErrorhook that retriesfetchMoreHistory(up to 12 attempts with 5s delay) until candles arrive, and adds unit tests covering retry/stop conditions.Written by Cursor Bugbot for commit 20ff264. This will update automatically on new commits. Configure here.