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

Error in fetch triggers pubsub error #229

Open
Hugo-Trentesaux opened this issue Apr 25, 2024 · 0 comments
Open

Error in fetch triggers pubsub error #229

Hugo-Trentesaux opened this issue Apr 25, 2024 · 0 comments

Comments

@Hugo-Trentesaux
Copy link

TL;DR A failing kubo1.dag.get(cid) triggers error in kubo2.pubsub.subscribe() .


I have two Kubo RPC instances:

// create RPC client only for dag fetch
const kubo1: KuboRPCClient = create({
  url: new URL(KUBO_RPC),
  agent: new Agent({
    maxSockets: 50000
  })
})
// create an other RPC client only for pubsub
export const kubo2: KuboRPCClient = create({
  url: new URL(KUBO_RPC),
  agent: new Agent({
    keepAlive: true,
    keepAliveMsecs: 1000
  })
})

First kubo2 is used for pubsub:

kubo2.pubsub.subscribe(TOPIC, handleMessage, {onError: pubsubErrorCallback}).catch(pubsubAbortCallback)

Then kubo1 is used to get dag:

kubo1.dag.get(cid).then(handleDag).catch(console.log)

The dag.get can timeout with UND_ERR_HEADERS_TIMEOUT (that's ok), but the problem is that this error seems to propagate to pubsub with UND_ERR_BODY_TIMEOUT, see the following stack trace:

+++ dag get error +++
TypeError: fetch failed
    at node:internal/deps/undici/undici:12344:11
    at Client.fetch (node_modules/.pnpm/kubo-rpc-client@4.1.1_undici@6.14.1/node_modules/kubo-rpc-client/src/lib/http.ts:149:42)
    at get (node_modules/.pnpm/kubo-rpc-client@4.1.1_undici@6.14.1/node_modules/kubo-rpc-client/src/block/get.ts:7:17)
    at Object.get (node_modules/.pnpm/kubo-rpc-client@4.1.1_undici@6.14.1/node_modules/kubo-rpc-client/src/dag/get.ts:29:19) {
  cause: HeadersTimeoutError: Headers Timeout Error
      at Timeout.onParserTimeout [as callback] (node_modules/.pnpm/undici@6.14.1/node_modules/undici/lib/dispatcher/client-h1.js:622:28)
      at Timeout.onTimeout [as _onTimeout] (node_modules/.pnpm/undici@6.14.1/node_modules/undici/lib/util/timers.js:22:13)
      at listOnTimeout (node:internal/timers:573:17)
      at process.processTimers (node:internal/timers:514:7) {
    code: 'UND_ERR_HEADERS_TIMEOUT'
  }
}
+++ pubsub error +++
TypeError: terminated
    at Fetch.onAborted (node:internal/deps/undici/undici:10916:53)
    at Fetch.emit (node:events:518:28)
    at Fetch.emit (node:domain:488:12)
    at Fetch.terminate (node:internal/deps/undici/undici:10102:14)
    at Object.onError (node:internal/deps/undici/undici:11034:38)
    at Request.onError (node_modules/.pnpm/undici@6.14.1/node_modules/undici/lib/core/request.js:298:27)
    at Object.errorRequest (node_modules/.pnpm/undici@6.14.1/node_modules/undici/lib/core/util.js:585:13)
    at Socket.<anonymous> (node_modules/.pnpm/undici@6.14.1/node_modules/undici/lib/dispatcher/client-h1.js:716:12)
    at Socket.emit (node:events:530:35)
    at Socket.emit (node:domain:488:12) {
  [cause]: BodyTimeoutError: Body Timeout Error
      at Timeout.onParserTimeout [as callback] (node_modules/.pnpm/undici@6.14.1/node_modules/undici/lib/dispatcher/client-h1.js:626:28)
      at Timeout.onTimeout [as _onTimeout] (node_modules/.pnpm/undici@6.14.1/node_modules/undici/lib/util/timers.js:22:13)
      at listOnTimeout (node:internal/timers:573:17)
      at process.processTimers (node:internal/timers:514:7) {
    code: 'UND_ERR_BODY_TIMEOUT'
  }
}
+++ pubsub abort +++
DOMException [AbortError]: This operation was aborted
    at node:internal/deps/undici/undici:12344:11
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at Client.fetch (node_modules/.pnpm/kubo-rpc-client@4.1.1_undici@6.14.1/node_modules/kubo-rpc-client/src/lib/http.ts:149:42)

I thought these two would be independent and an error on kubo1 fetch will not trigger an error on kubo2 sub. Is there a way to work around this with additional options like abort signal, timeout, or so?

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

1 participant