sentry-javascript: MaxListenersExceededWarning: Possible EventEmitter memory leak detected.

Package + Version

  • @sentry/node 5.30.0

Description

  1. When I use @sentry/node in Netlify functions, the console gets polluted with hundreds of MaxListenersExceededWarning warnings which makes any debugging impossible
  2. The exact message I get is after running netlify dev --inspect is:
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)

Most upvoted comments

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

@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)

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.

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.