alexbosworth / ln-service

Node.js interface to LND
MIT License
319 stars 60 forks source link

Possible memory leak using lnservice #137

Closed krtk6160 closed 3 years ago

krtk6160 commented 3 years ago

We use lnservice in our application that is used by around 500 users and have recently discovered a memory leak. While trying to find the root cause by looking at heap snapshots taken from our node.js app, we saw a lot of objects that look like lnd grpc objects created by lnservice. For example - image

Hundreds of such objects are present in the diff of snapshots taken before and after issuing multiple requests to our application. Afaik, the garbage collector is run right before a snapshot is taken, which means these objects are not getting garbage collected. This could mean that the memory leak is due to these objects. @alexbosworth Any ideas you might have that could help debug this issue will be greatly appreciated.

alexbosworth commented 3 years ago

You are re-using {lnd} object right? Don't create a new one for each call

krtk6160 commented 3 years ago

You are re-using {lnd} object right? Don't create a new one for each call

Yep, we are reusing the lnd object.

alexbosworth commented 3 years ago

Since you instantiate and supply the lnd object which is then passed around by reference, if you see multiple of them it is likely that it is something in your code that is creating multiple of them?

The ln-service methods do not create or clone this object as far as I know