js-kubo-rpc-client
js-kubo-rpc-client copied to clipboard
Frequent timeout errors with Node 20
Hey y'all. We've used this library with different NodeJS versions, and on the 20 LTS version, kubo-rpc-client throws timeout errors frequently whenever an RPC function is called. You don't have to call a specific function, it throws randomly.
An example code to produce:
import { create, urlSource } from "kubo-rpc-client";
const topicToTest = "test-topic" + Math.random();
(async () => {
const kuboClient = create("http://localhost:5001/api/v0");
let subscriptionCount = 0;
setTimeout(async () => {
const subscribedPubsubTopics = await kuboClient.pubsub.ls();
if (!subscribedPubsubTopics.includes(topicToTest)) {
await kuboClient.pubsub.subscribe(topicToTest, () => {}, {
onError: (err) => console.error(`Failed to pubsub subscribe`, err),
});
subscriptionCount++;
console.log(
`Subscribed to topic (${topicToTest}) for the ${subscriptionCount}th time`
);
}
}, 5000);
})();
Randomly you'd get a timeout error that looks like this
Failed to pubsub subscribe TypeError: terminated
at Fetch.onAborted (node:internal/deps/undici/undici:10917:53)
at Fetch.emit (node:events:518:28)
at Fetch.terminate (node:internal/deps/undici/undici:10102:14)
at Object.onError (node:internal/deps/undici/undici:11035:38)
at _Request.onError (node:internal/deps/undici/undici:7200:31)
at errorRequest (node:internal/deps/undici/undici:9765:17)
at Socket.onSocketClose (node:internal/deps/undici/undici:8927:9)
at Socket.emit (node:events:518:28)
at TCP.<anonymous> (node:net:337:12) {
[cause]: BodyTimeoutError: Body Timeout Error
at Timeout.onParserTimeout [as callback] (node:internal/deps/undici/undici:8855:32)
at Timeout.onTimeout [as _onTimeout] (node:internal/deps/undici/undici:6893:17)
at listOnTimeout (node:internal/timers:573:17)
at process.processTimers (node:internal/timers:514:7) {
code: 'UND_ERR_BODY_TIMEOUT'
}
}
Kubo: 0.24.0 kubo-rpc-client: 3.0.4 NodeJS: v20.11.1
Same for me. Is it linked to the "timeout" option (L471)? https://github.com/ipfs/js-kubo-rpc-client/blob/5c7e42ef02e9c9f8a509905fb22589107b158d2c/src/index.ts#L466-L476 The absence of documentation does not help :confused: (related to #113)
I've tested on Node 20, 18, and 16. 16 Doesn't have this issue, so I guess it's a compatibility problem between kubo-rpc-client and native fetch in node 18+