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:
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
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
And to run it:
/usr/bin/time -f 'elapsed=%e' node repro.mjsBehavior
fetchrejects immediately and the error is handled, so the process should exit immediately after printingcaught. Instead, it remains alive until the configured one-second timeout expires:The HTTP transport clears its abort timer only after
fetchand response parsing succeed. A rejection skips that cleanup and leaves the timer active until it fires.Proposed Solution
Clear the timer in
finallyso every exit path runs the cleanup:Tests should cover a rejected
fetch, rejected JSON parsing, success, and timeout.Environment
@ckb-ccc/core@1.17.0Impact
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