Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frequent timeout errors with Node 20 #220

Open
Rinse12 opened this issue Apr 6, 2024 · 2 comments
Open

Frequent timeout errors with Node 20 #220

Rinse12 opened this issue Apr 6, 2024 · 2 comments

Comments

@Rinse12
Copy link

Rinse12 commented Apr 6, 2024

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

@Hugo-Trentesaux
Copy link

Hugo-Trentesaux commented Apr 23, 2024

Same for me. Is it linked to the "timeout" option (L471)?

export interface Options {
host?: string
port?: number | string
protocol?: string
headers?: Headers | Record<string, string>
timeout?: number | string
apiPath?: string
url?: URL | string | Multiaddr
ipld?: Partial<IPLDOptions>
agent?: HttpAgent | HttpsAgent
}

The absence of documentation does not help 😕 (related to #113)

@Rinse12
Copy link
Author

Rinse12 commented Apr 24, 2024

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+

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

No branches or pull requests

2 participants