Repository navigation
Conversation
- Bound every chronik HTTP attempt with a 30s timeout: chronik-client sets none, so an unresponsive (rather than refusing) server hung callers forever. - Chronik calls made for web requests (balance, tx details, network status) share a 10s budget and fail with ChronikUnavailableError; the balance and tx routes answer 503. After one such failure, requests for that network fail fast for 30s instead of each waiting out the timeout. - Catch WS message handler failures, which were unhandled rejections (fatal in the jobs process) when chronik went down mid-block. - On-demand syncs fired from API routes never reject, and one network failing no longer loses the other's results. - The startup sync job skips a network whose chronik is unreachable instead of failing every address after retries, so the jobs waiting on it start. - When the WS only connects after failing at startup, backfill the subscribed addresses as on a reconnect, so outage txs aren't missed. - A failing chronik client setup no longer leaves startup waiting forever, and getUrls / getSubscribedAddresses work before the client is ready. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019G564i2sNiHJYQR95m8zGq
Contributor
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 50 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #851
Description
Fallback chronik URLs (#1010) cover one server going down. This PR covers every chronik server of a network being unreachable, refusing or hanging. In that case the web app and the jobs keep running, answer promptly, and pick back up when chronik returns.
What could go wrong before, and what changed:
chronikCallWithRetryis now bounded atCHRONIK_HTTP_ATTEMPT_TIMEOUT_MS(30s).getBalance,getTransactionDetails,getLastBlockTimestampfor the networks list) share aCHRONIK_REQUEST_TIMEOUT_MS(10s) budget.ChronikUnavailableError./api/address/balance/[address]and/api/transaction/[transactionId]answer 503CHRONIK_UNAVAILABLE_503instead of a 500 carrying the raw error. The transaction route also answers 400 for an unknown network slug, instead of crashing on an undefined client./api/networksreports the network asconnected: false, as before, but now promptly.CHRONIK_UNAVAILABLE_BACKOFF_MS(30s) instead of each waiting out the timeout. Any success clears this. A real chronik error, such as an unknown txid, does not trip it.onMessagedidvoid this.processWsMessage(msg), so a handler failing (e.g.syncBlockTransactionsonBLK_FINALIZEDwith chronik gone) was an unhandled rejection. Next.js only logs those, but the jobs process (plain Node) exits on them. They're now caught and logged.syncAndSubscribeAddresses, which API routes call withvoid, never rejects now.MultiBlockchainClient.syncAddresses/subscribeAddressescontain one network's failure, so the other network's results aren't lost.ChronikClient.useStrategyever throws, the client is left unset (its calls fail as unavailable) instead of leavingwaitForStart()and the jobs waiting forever.getUrls()(admin page SSR) andgetSubscribedAddresses()no longer throwTypeErrorbefore the client is ready.Test plan
make github-test-unit: 20 suites / 425 tests pass.tests/unittests/chronikDown.test.tsmocks chronik-client so that every HTTP call fails as "Error connecting to known Chronik instances" (or never answers) and the WS never opens. It checks:ChronikUnavailableError, then fail fast without calling chronik, then retry after the backoff, and a success clears the statesyncAndSubscribeAddressesresolvesgetUrls/getSubscribedAddresses/ calls behavesyncMissedTransactionstests stub the new reachability check.tsc --noEmitreports no new errors in the changed files.networkBlockchainURLs.ecashat an unreachable host (and one that accepts TCP but never answers, e.g.nc -l), start the app and jobs, and confirm:/api/networksreturns promptly withconnected: falseRemarks
skipDuplicates), as they do for a reconnect during startup today.utils/timeout.tsis the same file as in the health-checks PR, so the two merge cleanly in either order.WS_AUTH_KEYstill fails client setup (a config error, not an outage).Generated by Claude Code