Possible event listener memory leak
See original GitHub issueDisclaimer: I’m fairly new to Node 😃
The following event listener in CacheableRequest.js is never removed:
this.cache.on('error', err => ee.emit('error', new CacheableRequest.CacheError(err)));
These listeners will keep accumulating in the scenario where you are reusing a single CacheableRequest to service multiple requests (which I believe is the intention?).
Moreover, the error produced by the cache is not necessarily associated with the current request - it’s a generic error that is broadcast to all listeners.
IssueHunt Summary
clement-buchart has been rewarded.
Backers (Total: $80.00)
- issuehunt ($80.00)
Submitted pull Requests
Tips
- Checkout the Issuehunt explorer to discover more funded issues.
- Need some help from other developers? Add your repositories on IssueHunt to raise funds.
IssueHunt has been backed by the following sponsors. Become a sponsor
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:14 (4 by maintainers)
Top Results From Across the Web
Causes of Memory Leaks in JavaScript and How to Avoid ...
Common Sources of Memory Leaks in JavaScript Code # · 1. Accidental global variables · 2. Closures · 3. Timers · 4. Event...
Read more >addEventListener memory leaks - javascript
You will get memory leak if you delete from DOM, elements that have attached listeners. But this only occurs in ...
Read more >4 Types of Memory Leaks in JavaScript and How to Get Rid ...
The main cause for leaks in garbage collected languages are unwanted references. To understand what unwanted references are, first we need to ...
Read more >Are you afraid of event handlers because of C# memory ...
There is a lot of fear among many new developers about C# memory leak caused by event handlers. At some places, the idea...
Read more >How to escape from memory leaks in JavaScript
Garbage collector The main cause of memory leaks in an application is due to unwanted references. The garbage collector finds the memory that ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@issuehunt has funded $80.00 to this issue.
Hello, I think this is loosely related to this issue : https://github.com/sindresorhus/got/issues/792 I opened in got. In short, the fact that instantiating a new Keyv every time cacheableRequest is instantiated leads to a lot of eventListener being registered, causing a Memory leak for us. One could argue that given that cacheableRequest needs a ‘request’ function in it’s constructor, it’s not super easy to keep a single instance for an application.
It’s probably a naïve approach, but I see 2 potential solutions :
@lukechilds What do you think ? Any suggestion on how to fix this ? I would gladly open a MR.