Skip to content

[BUG] Failed HTTP Request Keeps Node Alive Until Timeout #450

Description

@phroi

Hello folks at CKB DevRel,

I noticed that a handled CCC HTTP request failure keeps a Node process alive until the request timeout expires.

Minimal Reproduction

import { ccc } from "@ckb-ccc/core";

globalThis.fetch = async () => {
  throw new Error("unavailable");
};

const client = new ccc.ClientPublicTestnet({
  url: "https://a.invalid/",
  fallbacks: [],
  timeout: 1000,
});

await client.getTip().catch(() => console.log("caught"));

And to run it:

/usr/bin/time -f 'elapsed=%e' node repro.mjs

Behavior

fetch rejects immediately and the error is handled, so the process should exit immediately after printing caught. Instead, it remains alive until the configured one-second timeout expires:

caught
elapsed=1.30

The HTTP transport clears its abort timer only after fetch and response parsing succeed. A rejection skips that cleanup and leaves the timer active until it fires.

Proposed Solution

Clear the timer in finally so every exit path runs the cleanup:

const aborter = new AbortController();
const abortTimer = setTimeout(() => aborter.abort(), this.timeout);

try {
  return await (
    await fetch(this.url, {
      method: "POST",
      headers: { "content-type": "application/json" },
      body: JSON.stringify(payload),
      signal: aborter.signal,
    })
  ).json();
} finally {
  clearTimeout(abortTimer);
}

Tests should cover a rejected fetch, rejected JSON parsing, success, and timeout.

Environment

  • @ckb-ccc/core@1.17.0
  • Node.js 24.18.0
  • Linux

Impact

A handled HTTP failure can delay a finite Node command, test, or worker until the request timeout expires. With the default timeout this can add about 30 seconds, and repeated failures can leave multiple active timers.

Keep up the Great Work
Phroi %47

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions