question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Possible event listener memory leak

See original GitHub issue

Issuehunt badges

Disclaimer: 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 clement-buchart has been rewarded.

Backers (Total: $80.00)

Submitted pull Requests


Tips


IssueHunt has been backed by the following sponsors. Become a sponsor

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
IssueHuntBotcommented, May 15, 2019

@issuehunt has funded $80.00 to this issue.


1reaction
clement-buchartcommented, May 10, 2019

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 :

  • Either allow a client to pass the Keyv instance in place of the Keyv adapter (which will need an additional boolean parameter in the constructor because Keyv and it’s adapter have nearly identical signature)
  • Keep a list of Keyv instance and, when provided with an adapter, check if a Keyv instance already exists for it

@lukechilds What do you think ? Any suggestion on how to fix this ? I would gladly open a MR.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found