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 just added @sentry/node as well to my Netlify project and am also experiencing this.
Having same issue with a setup of Sentry Lambda + Serverless + Serverless Offline + Webpack + GraphQL.
My difference is that the memory is consumed and I get a heap error. At first I thought I was making too many requests, which that would be fine, but it seems they are not being cleared. Disabling tracing did not change anything.
I was able to trace it to this:
at _addListener (events.js:390:17)
at ClientRequest.addListener (events.js:406:10)
at ClientRequest.once (events.js:437:8)
at wrappedMethod (***MY PATH***/code/api/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:105:1)
Regular request:
(node:91012) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [ClientRequest]. Use emitter.setMaxListeners() to increase limit
at _addListener (events.js:390:17)
at ClientRequest.addListener (events.js:406:10)
at ClientRequest.once (events.js:437:8)
at wrappedMethod (***MY PATH***/code/api/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:105:1)
at wrappedMethod (***MY PATH***/code/api/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/code/api/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/code/api/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/code/api/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/code/api/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/code/api/.webpack/service/src/lambda/bend/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/code/api/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/code/api/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/code/api/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/code/api/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/code/api/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/code/api/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at ***MY PATH***/code/api/.webpack/service/src/lambda/bend/webpack:/node_modules/node-fetch/lib/index.mjs:1432:1
at new Promise (<anonymous>)
at fetch (***MY PATH***/code/api/.webpack/service/src/lambda/bend/webpack:/node_modules/node-fetch/lib/index.mjs:1401:1)
at ***MY PATH***/code/api/.webpack/service/src/lambda/bend/webpack:/node_modules/apollo-link-http/lib/bundle.esm.js:69:1
at new Subscription (***MY PATH***/code/api/.webpack/service/src/lambda/bend/webpack:/node_modules/zen-observable/lib/Observable.js:197:1)
at Observable.subscribe (***MY PATH***/code/api/.webpack/service/src/lambda/bend/webpack:/node_modules/zen-observable/lib/Observable.js:279:1)
at ***MY PATH***/code/api/.webpack/service/src/lambda/bend/webpack:/node_modules/apollo-link-error/lib/bundle.esm.js:11:1
at new Subscription (***MY PATH***/code/api/.webpack/service/src/lambda/bend/webpack:/node_modules/zen-observable/lib/Observable.js:197:1)
at Observable.subscribe (***MY PATH***/code/api/.webpack/service/src/lambda/bend/webpack:/node_modules/zen-observable/lib/Observable.js:279:1)
at ***MY PATH***/code/api/.webpack/service/src/lambda/bend/webpack:/node_modules/apollo-client/bundle.esm.js:864:1
at new Subscription (***MY PATH***/code/api/.webpack/service/src/lambda/bend/webpack:/node_modules/zen-observable/lib/Observable.js:197:1)
at Observable.subscribe (***MY PATH***/code/api/.webpack/service/src/lambda/bend/webpack:/node_modules/zen-observable/lib/Observable.js:279:1)
at ***MY PATH***/code/api/.webpack/service/src/lambda/bend/webpack:/node_modules/apollo-client/bundle.esm.js:1001:144
at new Promise (<anonymous>)
at QueryManager.<anonymous> (***MY PATH***/code/api/.webpack/service/src/lambda/bend/webpack:/node_modules/apollo-client/bundle.esm.js:998:1)
at step (***MY PATH***/code/api/.webpack/service/src/lambda/bend/webpack:/node_modules/tslib/tslib.es6.js:100:1)
at Object.next (***MY PATH***/code/api/.webpack/service/src/lambda/bend/webpack:/node_modules/tslib/tslib.es6.js:81:45)
at ***MY PATH***/code/api/.webpack/service/src/lambda/bend/webpack:/node_modules/tslib/tslib.es6.js:74:1
at new Promise (<anonymous>)
at __awaiter (***MY PATH***/code/api/.webpack/service/src/lambda/bend/webpack:/node_modules/tslib/tslib.es6.js:70:1)
at QueryManager.module.exports../node_modules/apollo-client/bundle.esm.js.QueryManager.mutate (***MY PATH***/code/api/.webpack/service/src/lambda/bend/webpack:/node_modules/apollo-client/bundle.esm.js:950:25)
at ApolloClient.mutate (***MY PATH***/code/api/.webpack/service/src/lambda/bend/webpack:/node_modules/apollo-client/bundle.esm.js:2016:1)
at Object.mutate (***MY PATH***/code/api/.webpack/service/src/lambda/bend/webpack:/src/lambda/bend/clientManager.js:7:37)
at Object.create (***MY PATH***/code/api/.webpack/service/src/lambda/bend/webpack:/src/lambda/bend/helpers/bendMigration.js:15:30)
at Object.create (***MY PATH***/code/api/.webpack/service/src/lambda/bend/webpack:/src/lambda/bend/helpers/group.js:7:57)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at init (***MY PATH***/code/api/.webpack/service/src/lambda/bend/webpack:/src/lambda/bend/bendtables/groupTable.js:35:12)
at ***MY PATH***/code/api/.webpack/service/src/lambda/bend/webpack:/src/lambda/bend/index.js:146:13
at ***MY PATH***/code/api/.webpack/service/src/lambda/bend/webpack:/node_modules/@sentry/serverless/esm/awslambda.js:122:1
at InProcessRunner.run (***MY PATH***/code/api/node_modules/serverless-offline/dist/lambda/handler-runner/in-process-runner/InProcessRunner.js:199:24)
at LambdaFunction.runHandler (***MY PATH***/code/api/node_modules/serverless-offline/dist/lambda/LambdaFunction.js:325:20)
at hapiHandler (***MY PATH***/code/api/node_modules/serverless-offline/dist/events/http/HttpServer.js:521:18)
at module.exports.internals.Manager.execute (***MY PATH***/code/api/node_modules/@hapi/hapi/lib/toolkit.js:45:28)
at Object.internals.handler (***MY PATH***/code/api/node_modules/@hapi/hapi/lib/handler.js:46:20)
at exports.execute (***MY PATH***/code/api/node_modules/@hapi/hapi/lib/handler.js:31:20)
at Request._lifecycle (***MY PATH***/code/api/node_modules/@hapi/hapi/lib/request.js:312:32)
at Request._execute (***MY PATH***/code/api/node_modules/@hapi/hapi/lib/request.js:221:9)
And the performance tracker:
(node:91012) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 response listeners added to [ClientRequest]. Use emitter.setMaxListeners() to increase limit
at _addListener (events.js:390:17)
at ClientRequest.addListener (events.js:406:10)
at ClientRequest.once (events.js:437:8)
at wrappedMethod (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:91:1)
at wrappedMethod (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/.webpack/service/src/lambda/bend/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at ***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/node-fetch/lib/index.mjs:1432:1
at new Promise (<anonymous>)
at Object.fetch (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/node-fetch/lib/index.mjs:1401:1)
at Object.<anonymous> (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/apollo-server-core/dist/plugin/usageReporting/plugin.js:144:1)
at Generator.next (<anonymous>)
at ***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/apollo-server-core/dist/plugin/usageReporting/plugin.js:8:1
at new Promise (<anonymous>)
at module.exports../node_modules/apollo-server-core/dist/plugin/usageReporting/plugin.js.__awaiter (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/apollo-server-core/dist/plugin/usageReporting/plugin.js:4:1)
at async_retry_1.default.retries (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/apollo-server-core/dist/plugin/usageReporting/plugin.js:143:1)
at RetryOperation.runAttempt [as _fn] (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/async-retry/lib/index.js:41:1)
at RetryOperation.module.exports../node_modules/retry/lib/retry_operation.js.RetryOperation.attempt (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/retry/lib/retry_operation.js:112:1)
at run (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/async-retry/lib/index.js:54:1)
at new Promise (<anonymous>)
at Object.retry [as default] (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/async-retry/lib/index.js:57:1)
at Object.<anonymous> (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/apollo-server-core/dist/plugin/usageReporting/plugin.js:143:1)
at Generator.next (<anonymous>)
at fulfilled (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/apollo-server-core/dist/plugin/usageReporting/plugin.js:5:42)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
(node:91012) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [ClientRequest]. Use emitter.setMaxListeners() to increase limit
at _addListener (events.js:390:17)
at ClientRequest.addListener (events.js:406:10)
at ClientRequest.once (events.js:437:8)
at wrappedMethod (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:105:1)
at wrappedMethod (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/.webpack/service/src/lambda/bend/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at wrappedMethod (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/@sentry/node/esm/integrations/http.js:90:1)
at ***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/node-fetch/lib/index.mjs:1432:1
at new Promise (<anonymous>)
at Object.fetch (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/node-fetch/lib/index.mjs:1401:1)
at Object.<anonymous> (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/apollo-server-core/dist/plugin/usageReporting/plugin.js:144:1)
at Generator.next (<anonymous>)
at ***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/apollo-server-core/dist/plugin/usageReporting/plugin.js:8:1
at new Promise (<anonymous>)
at module.exports../node_modules/apollo-server-core/dist/plugin/usageReporting/plugin.js.__awaiter (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/apollo-server-core/dist/plugin/usageReporting/plugin.js:4:1)
at async_retry_1.default.retries (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/apollo-server-core/dist/plugin/usageReporting/plugin.js:143:1)
at RetryOperation.runAttempt [as _fn] (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/async-retry/lib/index.js:41:1)
at RetryOperation.module.exports../node_modules/retry/lib/retry_operation.js.RetryOperation.attempt (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/retry/lib/retry_operation.js:112:1)
at run (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/async-retry/lib/index.js:54:1)
at new Promise (<anonymous>)
at Object.retry [as default] (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/async-retry/lib/index.js:57:1)
at Object.<anonymous> (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/apollo-server-core/dist/plugin/usageReporting/plugin.js:143:1)
at Generator.next (<anonymous>)
at fulfilled (***MY PATH***/.webpack/service/src/lambda/graphql/webpack:/node_modules/apollo-server-core/dist/plugin/usageReporting/plugin.js:5:42)
at runMicrotasks (<anonymous>)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
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.
We've been having massive memory issues for a while, disabling sentry seems to have resolved them. This is not just a warning
I'm seeing the same thing with @sentry/node for Azure Functions. Disabling just the Http Integration fixes it. Here is the full stack trace that accompanies my warning:
(node:77) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 response listeners added to [ClientRequest]. Use emitter.setMaxListeners() to increase limit
at _addListener (events.js:390:17)
at ClientRequest.addListener (events.js:406:10)
at ClientRequest.once (events.js:437:8)
at wrappedMethod (/home/site/wwwroot/node_modules/@sentry/node/src/integrations/http.ts:127:10)
at /home/site/wwwroot/node_modules/node-fetch/lib/index.js:1438:15
at new Promise (<anonymous>)
at fetch (/home/site/wwwroot/node_modules/node-fetch/lib/index.js:1407:9)
at NodeFetchHttpClient.<anonymous> (/home/site/wwwroot/node_modules/@azure/core-http/dist/index.js:2659:39)
at step (/home/site/wwwroot/node_modules/tslib/tslib.js:140:27)
at Object.next (/home/site/wwwroot/node_modules/tslib/tslib.js:121:57)
This is how I avoided the issue:
Sentry.init{{
...config,
integrations: defaults => defaults.filter(integration => integration.name !== "Http")
})
@derekrprice I tested it locally, and the only way it can end up in this state is if Azure is purging require cache for each request, making our "installed integrations" list being purged. This makes setupOnce function on HTTP integration being called multiple times, thus wrapping http module multiple times. It should never happen in a healthy environment 🤔
@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.
Yeah, I have a little more work to do to instrument the API services being called by the function for tracing, but I'm not getting any error messages after re-enabling the HTTP integration. This is only a problem for me during automated testing.
Closing the issue as a part of large repository cleanup, due to it being inactive and/or outdated. Please do not hesitate to ping me if it is still relevant, and I will happily reopen and work on it. Cheers!
It is still happening. We are still waiting for the fix
@michalhudecek are you able to provide any kind of local repro?
@kamilogorek Unfortunately not. It is happening in Netlify functions and you need to have the website connected to the Netlify account to make it work locally.

Got fixed by upgrading netlify-cli to https://github.com/netlify/cli/releases/tag/v5.2.0
Oh, I wonder what was the main issue here. Thanks for letting us know!
Actually, looks like it was a false positive. It is still there. Is there anything else I could give you to help you identify the issue? Is there anyone on your team who works with Netlify?
Ever since version 6.9.0 we are also seeing this warning about a possible memory leak. We are not using netlify and everything was good up through version 6.8
Turns out in 6.9 the logic for autoSessionTracking in sentry/node was changed which caused it to default to true. Setting it to false explicitly makes this event emitter warning/error go away. Not sure why the error happens with it set to true though
@Logikgate if not netlify, what is your setup? Is there a chance to get some logs from the app? Session tracking is attaching a handler the history API, but it should be performed only once.
This issue has gone three weeks without activity. In another week, I will close it.
But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!
"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀
I'm still seeing this. Usually only when I'm running with next.js within the VSCode terminal