sentry-javascript: MaxListenersExceededWarning: Possible EventEmitter memory leak detected.
Package + Version
@sentry/node5.30.0
Description
- When I use
@sentry/nodein Netlify functions, the console gets polluted with hundreds of MaxListenersExceededWarning warnings which makes any debugging impossible - The exact message I get is after running
netlify dev --inspectis:
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 response listeners added to [ClientRequest]. Use emitter.setMaxListeners() to increase limit
node_modules/@sentry/node/esm/integrations/console.js
The issue was originally reported to Netlify as well https://github.com/netlify/cli/issues/1701
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 10
- Comments: 24 (8 by maintainers)
It is still happening. We are still waiting for the fix
Found and resolved my issue, which was due to how I was initializing Sentry as a winston transport. Turns out that running
new Sentryevery time you import your logger will take you over the 10 listener limit pretty quickly. I turned it up to 50 for each listener that gets registered, and haven’t seen the warning since.I do think that this library could do a better job of catching this, as the setupOnce isn’t operating like a true singleton.
@kamilogorek Something like that was probably happening. I was encountering the error inside my automated test suite, which was probably resetting the require cache for every test, as you said. Anyhow, now that I have the code setup correctly, I have no reason to run sentry in the test environment anymore, so I will attempt to enable the HTTP integration just in prod and verify it is working there. Should have results in an hour or two.
I’m experiencing something similar with serverless functions running on azure. I’ve tried setting autoSessionTracking to false (per https://github.com/getsentry/sentry-javascript/issues/3247#issuecomment-918668190), upgrading serverless-offline (per https://github.com/getsentry/sentry-javascript/issues/3247#issuecomment-806905276) and turning off HttpContext integration (per https://github.com/getsentry/sentry-javascript/issues/3247#issuecomment-824071821). None resolve the issue.
Error messages are like this (with --trace-warnings set)
Any other ideas @kamilogorek or Sentry team? Definitely seems like setupOnce is happening more than once.
I’m still seeing this. Usually only when I’m running with next.js within the VSCode terminal
In my case, it turned out to be a memory leak on serverless-offline v6.8.0. Going back to 6.5.0 fixes the issues.