Closed JoshMock closed 1 month ago
@ronag Since you were helpful in digging into this issue with your knowledge of Undici, I'd love a quick review from you if you have the time. :pray:
I'm unsure why you don't just pass null if there is no signal?
Because the code implements per-request timeout functionality, so it needs a signal to manually abort the request when the timeout is reached. @delvedor discussed adding this to the Undici library https://github.com/nodejs/undici/issues/165 but the functionality never shipped, so he added similar logic to do the same thing here.
Does it breaks code which uses emitter(which is removed)?
Does it breaks code which uses emitter(which is removed)?
The use of EventEmitter
is an internal implementation detail, not something exposed to end users, so removing it does not break the public contract.
A potential fix for https://github.com/elastic/elastic-transport-js/issues/63, largely inspired by a community member's PR that was never merged: https://github.com/elastic/elastic-transport-js/pull/55
According to an Undici core committer in this comment the issue that triggers the
MaxListenersExceededWarning
, and possibly a memory leak in some cases, is caused by attaching anEventEmitter
to each request by default when a per-request timeout is set, rather than attaching anAbortSignal
.My assumption is that an
EventEmitter
was used becauseAbortSignal
andAbortController
were not added to Node.js until v14.17.0, so we couldn't guarantee v14 users would have it. I'm not certain why usingEventEmitters
makes a difference memory-wise, but it does get rid of theMaxListenersExceededWarning
.