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
I'm also experiencing this still. I'm using Netlify Functions.
@sentry/node": "^6.10.0 netlify-cli 6.14.19
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)
2022-10-26T13:59:48.807 [Warning] (node:3044) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 uncaughtException listeners added to [process]. Use emitter.setMaxListeners() to increase limit
2022-10-26T13:59:48.807 [Information] at _addListener (events.js:389:17)
2022-10-26T13:59:48.807 [Information] at process.addListener (events.js:405:10)
2022-10-26T13:59:48.807 [Information] at onuncaughtexception_OnUncaughtException.setupOnce (C:\home\site\wwwroot\src\handlers\OperationHandler.js:3020:124677)
2022-10-26T13:59:48.807 [Information] at C:\home\site\wwwroot\src\handlers\OperationHandler.js:3020:92504
2022-10-26T13:59:48.807 [Information] at Array.forEach (<anonymous>)
2022-10-26T13:59:48.807 [Information] at setupIntegrations (C:\home\site\wwwroot\src\handlers\OperationHandler.js:3020:92366)
2022-10-26T13:59:48.808 [Information] at client_NodeClient.setupIntegrations (C:\home\site\wwwroot\src\handlers\OperationHandler.js:3020:95644)
2022-10-26T13:59:48.808 [Information] at hub_Hub.bindClient (C:\home\site\wwwroot\src\handlers\AnalysisHandler.js:3021:65525)
2022-10-26T13:59:48.808 [Information] at initAndBind (C:\home\site\wwwroot\src\handlers\OperationHandler.js:3020:112916)
2022-10-26T13:59:48.808 [Information] at Module.init (C:\home\site\wwwroot\src\handlers\OperationHandler.js:3020:153639)
2022-10-26T13:59:48.808 [Information] at new SentryTransport (C:\home\site\wwwroot\src\handlers\OperationHandler.js:1592:5920909)
2022-10-26T13:59:48.808 [Information] at mkOptions (C:\home\site\wwwroot\src\handlers\OperationHandler.js:30:30493)
Any other ideas @kamilogorek or Sentry team? Definitely seems like setupOnce is happening more than once.
@jlev if you are able to produce a repro-case for that issue, please do so and include it in new issue. Thanks
Found and resolved my issue, which was due to how I was initializing Sentry as a winston transport. Turns out that running new Sentry every 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.