-
Notifications
You must be signed in to change notification settings - Fork 654
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
Likely memory leak in internal-channel.ts #2436
Comments
Just noticed this issue, which is very similar. I'm going to study that issue to see if we're falling into a similar trap. |
I will just note that the |
You're right @murgatroid99 -- I've tried closing the clients and that has helped enormously. But even then, we still do have a lot of
That's entirely possible. Our system makes calls using many different refresh_tokens -- out of 1000 api calls, we'll be using perhaps 200 different refresh tokens. Is it possible to re-use a We're using google-gax as a wrapper, and it's possible that its generated code doesn't use grpc.js optimally for our use-case. Here's an example of google-gax's generated code (the part that initialises the GRPC client):
And ultimately, this is how we load the GRPC client services: https://github.com/Opteo/google-ads-api/blob/master/src/service.ts#L94 (the only option we pass in is Does anything stick out as bad practice here? Perhaps we should be passing in the Thanks so much for your help! |
It seems like the It is possible that there is a bug with channelz here. If you construct the client with the option |
Indeed, but we're instantiating the whole
I'm not sure how we would set I consider this problem solved 👍 . Thanks for your help! |
Problem description
Hi there! I'm a maintainer of the google-ads-node library, which depends on
@grpc/grpc-js
.Every call to the google ads API leaves behind a bit of unreclaimed memory. Looking into it, it seems to be related to the
internal-channel.ts
file'ssetInterval()
call. In the screenshot below, there are 13 calls to the google ads API, and indeed 13 instances ofClientHttp2Session
hanging around well after the call is over.I took a look at the file, and from my limited understanding, this could be the culprit: https://github.com/grpc/grpc-node/blob/master/packages/grpc-js/src/internal-channel.ts#L191. The
setInterval
ID is never cleared, causing V8 to keep a reference tothis
forever, which includes the entireInternalChannel
class. Unref'ing the setInterval doesn't change that behaviour as far as I can tell.Reproduction steps
This isn't super tight, but here's how I reproduce the problem:
google-ads-api
from NPMwhile(true)
loop, make a.report([params])
or.query([params])
call to the Google Ads API, making sure toawait
so it only does one at a timenode --inspect script.js
& attach the chrome debuggergrpc-js
Environment
Additional context
There are a number of other objects in the heap that aren't able to be garbage collected due to
intenal-channel
. Here's another one:In production, this causes our nodejs processes to crash every few hours once they fill the available memory:
I can provide the full heap timeline file, as well as any other information upon request :)
The text was updated successfully, but these errors were encountered: