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.

MaxListenersExceededWarning when trying to resolve more than 10 URLs

See original GitHub issue

When 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:open
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
broekercommented, Nov 29, 2019

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:

  let offset = 0;
  items.map(item => {
    setTimeout(() => {
    (async () => {
      await captureWebsite.file(item[0], './screenshots/' + item[1] + '.png', options);
    })();
    }, 10000 + offset);
    offset += 10000;
  })

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 😃

2reactions
sindresorhuscommented, Mar 30, 2021

Even easier to use p-map with its concurrency option.

Read more comments on GitHub >

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

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