Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MaxListenersExceededWarning: Possible EventEmitter memory leak detected. error #1027

Closed
apatora opened this issue Sep 11, 2019 · 22 comments
Closed

Comments

@apatora
Copy link

apatora commented Sep 11, 2019

Problem description

I am using the package @google-cloud/bigtable which relies on this one and when I ran npm install today it updated @grpc/grpc-js from 0.5.2 to 0.5.3. I am getting the following error :

MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added. Use emitter.setMaxListeners() to increase limit
    at _addListener (events.js:256:17)
    at TLSSocket.addListener (events.js:272:10)
    at TLSSocket.Readable.on (_stream_readable.js:826:35)
    at Http2CallStream.attachHttp2Stream (/usr/src/node_modules/@google-cloud/bigtable/node_modules/@grpc/grpc-js/build/src/call-stream.js:275:35)
    at Http2SubChannel.startCallStream (/usr/src/node_modules/@google-cloud/bigtable/node_modules/@grpc/grpc-js/build/src/subchannel.js:110:20)
    at finalMetadata.then.metadataValue (/usr/src/node_modules/@google-cloud/bigtable/node_modules/@grpc/grpc-js/build/src/channel.js:205:28)
    at process._tickCallback (internal/process/next_tick.js:68:7)

Reproduction steps

Run npm i @google-cloud/bigtable in a project. Then try to execute for example :

const Bigtable = require('@google-cloud/bigtable')

for (let j = 0; j < 100; j++) {
    Bigtable.instance('INSTANCE').table('TABLE').insert([{ key: 'key', data: { data: { some: 'data' } } }]
}

Environment

I am running the code in the following docker image : node:10.16.0

@murgatroid99
Copy link
Member

I think this is the result of #1021. I'll need to figure out a better way to do that.

@ddehghan
Copy link

ddehghan commented Sep 16, 2019

also happens on node:12.10.0-alpine

 MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [TLSSocket]. Use emitter.setMaxListeners() to increase limit
    at _addListener (events.js:267:17)
    at TLSSocket.addListener (events.js:283:10)
    at TLSSocket.Readable.on (_stream_readable.js:863:35)
    at Http2CallStream.attachHttp2Stream (/var/www/app/node_modules/@grpc/grpc-js/build/src/call-stream.js:275:35)
    at Http2SubChannel.startCallStream (/var/www/app/node_modules/@grpc/grpc-js/build/src/subchannel.js:110:20)
    at /var/www/app/node_modules/@grpc/grpc-js/build/src/channel.js:205:28

@ddehghan
Copy link

for now i rolled back to ver "0.5.2" and it fixed the problem.

@yatingoswami
Copy link

Also facing the same issue on 12.4.0-stretch
Getting pod restarts every 4 hours.

Cant rollback version as its part of google-gax which is nested inside @google-cloud/pubsub.
Is there a proper solution for this

@apatora
Copy link
Author

apatora commented Sep 18, 2019

@yatingoswami You can solve the issue for now by putting :

"resolutions": {
  "@grpc/grpc-js": "0.5.2"
}

in your package.json file. Then you execute npx npm-force-resolutions and npm i.

It seems that the issue is affecting a lot of packages. Maybe it would be better to rollback #1021 until it is fully resolved.

@nicolasnoble
Copy link
Member

How is a warning impeding production usage exactly?

@yatingoswami
Copy link

yatingoswami commented Sep 18, 2019

"resolutions": { "@grpc/grpc-js": "0.5.2" }
This solved it for me.
Thanks

@merlinnot
Copy link
Contributor

How is a warning impeding production usage exactly?

There's a massive memory leak. This warning is accurate. I observed consumption of ~1GB/h/instance across 200+ Google Cloud Functions (1k+ instances), causing so many OOMs that the retry mechanism gave up.

This is a severe issue and I highly recommend downgrading to 0.5.2, which does not have this leak.

@murgatroid99
Copy link
Member

In the past we have had various reports of this specific warning in other code paths, and in general it has not been indicative of memory leaks, but simply that there are more than 11 calls open simultaneously in a single channel. Because the warning was the only thing reported here, I assumed that that was the only user-facing symptom. Now that I know that there is a memory leak, I can investigate that and deploy a fix.

@merlinnot
Copy link
Contributor

Thanks, I thought it's being worked on and was just patiently waiting :)

It should be very easy to reproduce, but just in case you can't, I can provide a repro (although there are some code samples in this thread already).

@murgatroid99
Copy link
Member

grpc-js version 0.5.4 is now out with the fix for this.

@jrthib
Copy link

jrthib commented Sep 20, 2019

@murgatroid99 looks like the build is failing

@murgatroid99
Copy link
Member

If you're referring to the version bump build, that's just because I merged it quickly.

@merlinnot
Copy link
Contributor

I can confirm that there's no memory leak anymore.

@kirillgroshkov
Copy link

We still have these errors in production (screenshot from today attached). We're using Datastore node library.

yarn list @grpc/grpc-js                                                            01:37 Dur
yarn list v1.17.3
warning Filtering by arguments is deprecated. Please use the pattern option instead.
└─ @grpc/grpc-js@0.5.4
✨  Done in 0.74s.

image

@murgatroid99
Copy link
Member

What is the call stack for those errors? I removed the line of code that caused the original errors; it doesn't exist in version 0.5.4.

@jakeleventhal
Copy link

I am on 5.2 as per recommended and am seeing a MASSIVE memory leak from something different that may be related. googleapis/nodejs-firestore#768

@apatora
Copy link
Author

apatora commented Oct 3, 2019

I tried the last version of this module and got the following error after a while :

Error: No connection established
    at Http2CallStream.call.on (/usr/src/node_modules/@google-cloud/bigtable/node_modules/@grpc/grpc-js/build/src/call.js:68:41)
    at Http2CallStream.emit (events.js:203:15)
    at Http2CallStream.EventEmitter.emit (domain.js:448:20)
    at process.nextTick (/usr/src/node_modules/@google-cloud/bigtable/node_modules/@grpc/grpc-js/build/src/call-stream.js:75:22)
    at process._tickCallback (internal/process/next_tick.js:61:11)

@murgatroid99
Copy link
Member

@apatora that looks like an entirely separate error. I suggest filing a separate issue with more details.

@nekdev
Copy link

nekdev commented Oct 6, 2019

I tried the last version of this module and got the following error after a while :

Error: No connection established
    at Http2CallStream.call.on (/usr/src/node_modules/@google-cloud/bigtable/node_modules/@grpc/grpc-js/build/src/call.js:68:41)
    at Http2CallStream.emit (events.js:203:15)
    at Http2CallStream.EventEmitter.emit (domain.js:448:20)
    at process.nextTick (/usr/src/node_modules/@google-cloud/bigtable/node_modules/@grpc/grpc-js/build/src/call-stream.js:75:22)
    at process._tickCallback (internal/process/next_tick.js:61:11)

@apatora I'm facing the same error in Google Cloud Functions. Did you find any workaround?

@apatora
Copy link
Author

apatora commented Oct 6, 2019

@nekdev You should check #1064. For now the only way to circumvent this error is to force (in package.json) :

"resolutions": {
    "@grpc/grpc-js": "0.5.2",
    "google-gax": "1.6.2"
}

I am closing this issue as it seems the MaxListenersExceededWarning is gone in the newest versions of grpc-js.

@apatora apatora closed this as completed Oct 6, 2019
@nekdev
Copy link

nekdev commented Oct 7, 2019

All problems solved after updating to:

    "firebase-admin": "^8.6.0",
    "firebase-functions": "^3.2.0",

@lock lock bot locked as resolved and limited conversation to collaborators Jan 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants