-
Notifications
You must be signed in to change notification settings - Fork 541
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
fix(fetch): remove terminated event listener on redirect #1715
fix(fetch): remove terminated event listener on redirect #1715
Conversation
Codecov ReportBase: 89.55% // Head: 89.55% // Increases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## main #1715 +/- ##
=======================================
Coverage 89.55% 89.55%
=======================================
Files 58 58
Lines 5257 5258 +1
=======================================
+ Hits 4708 4709 +1
Misses 549 549
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
Could you add a unit test? |
The code looks good. I would remove the individual listener and not all. |
For now... I think it's easier just to increase the listener limit, i.e. |
I tried doing this in the
Is there an easy way of checking if a warning was emitted? |
* fix(fetch): remove terminated event listener on redirect * fix: use setMaxListeners instead * Update lib/fetch/index.js Co-authored-by: Robert Nagy <[email protected]>
Did this PR actually fix anything or did it just mask the problem so that an annoying message got printed less frequently? |
Masked the issue. |
I'll have a PR that actually fixes it, wasn't that complicated. |
Could I clarify, Is there is an actual issue with event listeners being added but not removed in the presence of redirect responses? |
its not like you have a memory leak. When fetch is ending, it garbage collects the instance and all the open listeners are garbage collected too. |
ok, so the emission of the messages was simply caused by bursty acquisition of listeners prior to GC occurring? |
Basically. An EventEmitter could have hundreds of listeners for a single event without being an issue. But the case is very rare, so the node core devs decided to warn the devs if they add more than 10 listeners to an event without maybe actively noticing it, as it indicates a bug, which could slow down the performance, without being that obvious while you are developing. |
* fix(fetch): remove terminated event listener on redirect * fix: use setMaxListeners instead * Update lib/fetch/index.js Co-authored-by: Robert Nagy <[email protected]>
Disclaimer: this is a pretty terrible solution, but I couldn't find another way of fixing this.
Fixes #1711
undici/lib/fetch/index.js
Line 1813 in 7102eb0
onAborted
outside of this scope as it relies onresponse
, and if we use a closure (etc.) the same problem would happen.undici/lib/fetch/index.js
Line 2028 in 7102eb0
If you have any idea of how to fix this, please let me know. I spent maybe 45 minutes trying anything I could think of.
Also not sure how I would add tests for this.