Skip to content

fix: bound Insight, JSON-RPC and faucet requests with deadlines - #38

Merged
PastaPastaPasta merged 2 commits into
mainfrom
fix/bound-request-deadlines
Oct 7, 2026
Merged

PastaPastaPasta merged 2 commits into
mainfrom
fix/bound-request-deadlines

Conversation

@PastaPastaPasta

@PastaPastaPasta PastaPastaPasta commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Insight, the JSON-RPC InstantSend endpoint and the faucet were called with await fetch(...) and then await response.json(), with no per-request deadline. Elapsed-time and abort checks only ran between requests. A server that accepts the connection but never finishes the headers or the body could therefore hang deposit detection. Worse, it could hang the InstantSend wait after the asset lock had already been broadcast, so the 60s IS-lock timeout and the chain-lock recovery path were never reached. This was reported by a security review (findings 10 and 11, low severity).

Change

Every one of those requests now has a deadline that covers both the headers and the body read:

Call Deadline
Insight UTXO, block-height and transaction reads 8s
Insight broadcast 20s
JSON-RPC getislocks / getbestchainlock 8s
Faucet status / request 30s (existing timeout, now also covers the body)
  • IS-lock wait. DAPIClient.waitForInstantSendLock now settles at exactly its deadline, even if the deadline falls during a retry backoff. When it does, it cancels the request that's in flight, so the existing error, recovery and chain-lock fallback paths run.
  • Faucet POST. It is still never retried automatically. If the faucet replies 2xx but the body stalls, the error now says funds may already be on the way, so the user doesn't request a second payout.
  • Broadcast. A timeout may be retried by withRetry. That's safe because re-sending the same signed transaction is idempotent.

Coordination with #37

src/utils/fetch-json.ts is byte-identical to the helper in #37. That PR is a larger rework that removes the Digital Cash RPC dependency. A simulated merge conflicts only in insight.ts (imports and getTransaction) and dapi.ts (waitForInstantSendLock, which #37 rewrites).

Testing

  • npm test passes, with 17 new tests in src/utils/fetch-with-deadline.test.ts and src/api/request-deadlines.test.ts. They cover:
    • a request that never gets a response;
    • a body that never finishes;
    • caller abort forwarding;
    • a 60s IS-lock wait through the real IslockService that rejects at exactly 60,000ms;
    • a deadline that lands mid-backoff;
    • faucet stalls before and after a response.
  • 8 of the 9 new API tests fail against the old code. The one that passes is the broadcast error-text check, which is meant to pass on both.
  • npm run build and npm run test:e2e pass.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Reliability
    • Network requests now time out consistently, including when response data is slow to arrive, and can be cancelled when no longer needed.
    • Blockchain status polling now stops promptly when cancelled and retries only errors that may succeed on a later attempt.
  • Bug Fixes
    • Faucet requests provide clearer guidance when a successful request’s response cannot be read, and retain retry-delay details for applicable rate limits.

Fetches to Insight, the JSON-RPC InstantSend endpoint and the faucet had
no deadline on response headers or body. A server that accepted the
connection but never finished could hang deposit detection, or hang the
IS-lock wait after broadcast so the 60s timeout and chain-lock fallback
were never reached.

- Add src/utils/fetch-json.ts, identical to the helper in #37, and a
  sibling fetchWithDeadline for call sites that need the raw Response.
- Insight reads: 8s; broadcast: 20s, keeping its error text.
- JSON-RPC getislocks/getbestchainlock: 8s. The IS-lock wait now
  cancels the in-flight request and settles exactly at its deadline or
  on caller abort, even mid retry backoff.
- Faucet: the existing 30s timeout now also covers the body read; a
  stalled body after a 2xx tells the user funds may already be sent.
- Forward the chain-lock fallback's abort signal to tx polling.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You'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 49 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: aba5aaf5-f9ee-4025-a96f-69c67de964a4
📥 Commits

Reviewing files that changed from the base of the PR and between 25a6c85 and 3feaa8d.

📒 Files selected for processing (3)
  • src/api/insight.ts
  • src/api/request-deadlines.test.ts
  • src/main.ts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d887ba7f-d180-44b6-97d1-83ad364c9aff
📥 Commits

Reviewing files that changed from the base of the PR and between ab04c2f and 25a6c85.

📒 Files selected for processing (7)
  • src/api/dapi.ts
  • src/api/faucet.ts
  • src/api/insight.ts
  • src/api/request-deadlines.test.ts
  • src/utils/fetch-json.ts
  • src/utils/fetch-with-deadline.test.ts
  • src/utils/fetch-with-deadline.ts

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


📝 Walkthrough

Walkthrough

Request utilities and API clients now apply deadlines and cancellation to network requests and response reads. Insight, DAPI, and faucet request flows handle timeout and abort outcomes, with tests covering stalled requests, stalled response bodies, and polling cancellation.

Changes

Request deadlines

Layer / File(s) Summary
Shared request deadline helpers
src/utils/fetch-with-deadline.ts, src/utils/fetch-json.ts, src/utils/fetch-with-deadline.test.ts
Adds helpers that apply timeouts and caller cancellation to fetch requests and response reads. Tests cover timeout and abort behavior.
Insight requests and polling
src/api/insight.ts, src/api/request-deadlines.test.ts
Insight reads use fetchJson, broadcasts use fetchWithDeadline, and transaction polling forwards cancellation and limits retries. Tests cover timeouts and polling cancellation.
DAPI requests and InstantSend-lock polling
src/api/dapi.ts, src/api/request-deadlines.test.ts
DAPI JSON-RPC requests use fetchJson. InstantSend-lock polling applies a deadline, aborts active work, and retries only retryable errors while active. Tests cover deadline and caller cancellation.
Faucet request and response deadlines
src/api/faucet.ts, src/api/request-deadlines.test.ts
Faucet status and funding requests include response-body reads within the timeout. Funding requests distinguish failures before and after acceptance. Tests cover stalled headers and bodies.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 25a6c

The change is mergeable. In one narrow case, cancelling block-height polling may take a few seconds to finish.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 12 functions across 7 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding deadlines to Insight, JSON-RPC, and faucet requests.
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.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

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

A broadcast that hits its new deadline may still have reached the node.
Failing there skipped setTransactionBroadcast, so the error screen had no
txid and hid the chain-lock fallback. Treat timeouts (and the 'already in
block chain' reply to a retry of a mined tx) as an unknown outcome and
continue to the IS lock wait with the locally computed txid.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@PastaPastaPasta
PastaPastaPasta merged commit 1f4180c into main Oct 7, 2026
4 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.

1 participant