grpc-node: MaxListenersExceededWarning: Possible EventEmitter memory leak detected. error

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

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 6
  • Comments: 22 (10 by maintainers)

Most upvoted comments

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

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

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.

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

@nekdev You should check https://github.com/grpc/grpc-node/issues/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.

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