MaxListenersExceededWarning when trying to resolve more than 10 URLs
See original GitHub issueWhen I invoke code:
const urlsArray = [] // more than 10 items
let imagePromises = []
urlsArray.forEach(item => {
const imagePath = `./tmp/${item.id}.jpg`
const captureWebsitePromise = captureWebsite.file(item.url, imagePath, {
width: 1280,
height: 800,
type: "jpeg",
overwrite: true
})
imagePromises.push(captureWebsitePromise)
}
})
Promise.all(imagePromises).then(function(imageResult) {
})
I have these errors:
(node:9535) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 exit listeners added to [process]. Use emitter.setMaxListeners() to increase limit
(node:9535) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGINT listeners added to [process]. Use emitter.setMaxListeners() to increase limit
(node:9535) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGTERM listeners added to [process]. Use emitter.setMaxListeners() to increase limit
(node:9535) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGHUP listeners added to [process]. Use emitter.setMaxListeners() to increase limit
Do you have an idea how to capture more than 10 pages using your module?
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Possible EventEmitter memory leak detected. 11 message lis ...
The default limit for Event Emitter is 10. You can increase it with the emitter.setMaxListeners. My suggestion is not to change it unless ......
Read more >possible EventEmitter memory leak detected - Marketing Nation
The warning is about event listeners. Not fired events. You have a loop that's adding the event listener over and over again, instead...
Read more >Events | Node.js v19.3.0 Documentation
Once the event is emitted, the listener is unregistered and then called. ... By default EventEmitter s will print a warning if more...
Read more >use emitter.setmaxlisteners() to increase limit - You.com
Use emitter.setMaxListeners () to increase limit. I have understood that I have more than 10 listeners to event and this is a node.js...
Read more >Node.js sends warnings when you add too many listeners to ...
Let's change the code above and add a few more event handlers. ... 0 1 2 3 4 5 6 7 8 9...
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 Free
Top 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

This might not be ideal but after messing around with numerous other approaches, I finally found a very simple solution that will allow me to spin through 50 sites (and presumably more) on a cheap server:
It seems for me the key is to wait 10 seconds between captures to give my server some breathing room. Three seconds was not long enough, I may be able to go lower but 10 seconds and it seems to chug right along with no error.
Note that this code does NOT need the unlimited listeners code i posted above, see here for a good discussion and particularly this comment:
https://stackoverflow.com/a/44446859/11777731
YMMV and if you have stronger server you may not need this but after a few days I can finally set a nightly cron with more than a few sites 😃
Even easier to use
p-mapwith itsconcurrencyoption.