Bug: Too much event listeners attached to an AbortSignal
- Dominant language
- JavaScript
- Stars
- 25
- Forks
- 30
- PR merge metrics
- No merged PRs in 30d
Description
Let's assume you call `ipfs.dag.get(cid, '/s/o/m/e/v/e/r/y/l/o/n/g/p/a/t/h', {signal: abortSignal})` where `ipfs` is an IPFS HTTP Client. The control flow would eventually go to `ipfs-http-client` [`resolve`](https://github.com/ipfs/js-ipfs/blob/master/packages/ipfs-http-client/src/lib/resolve.js#L17) function, and then end up in [`src/http.js` fetch function](https://github.com/ipfs/js-ipfs-utils/blob/master/src/http.js#L94) of this package.
Every path element would [add an event listener](https://github.com/ipfs/js-ipfs-utils/blob/master/src/http.js#L131) to the original `abortSignal`. Eventually, if the path is long enough, Node.js starts emitting `MaxListenersExceededWarning` warnings. I consider this a bug.
Now [any-signal](https://github.com/jacobheun/any-signal) library allows you to clear event listeners after use. The solution to the warnings problem might be to call `signal.clear` after [response](https://github.com/ipfs/js-ipfs-utils/blob/master/src/http.js#L140) is done. I would happily contribute, yet any-signal can not really be used here due to CJS/ESM incompatibility: You can not use ESM any-signal from CJS js-ipfs-utils package. See also: https://github.com/ipfs/js-ipfs-utils/issues/266
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.