[Resolved] Meteor.bindEnvironment memory leak?


#1

My app’s memory usage was a rock solid ~180MB ever since launch over a month ago (Mid-Dec). On the 24th of January I noticed an error in Kadira resulting from the following (simplified) snippet:

memCache.on('del', docId => {
  memCache.set(docId, Collection.find({ docId }).fetch());
});

Unfortunately, I don’t have the error handy but after a quick google it became evident that I needed to wrap the callback using Meteor.bindEnvironment (which did resolve the error):

memCache.on('del', Meteor.bindEnvironment(docId => {
  memCache.set(docId, Collection.find({ docId }).fetch());
}));

Ever since that deployed fix my memory usage has slowly climbed at a rate of approx 40MB a day. This was the only code change in that update.

What can I do? Can I remove the bindEnvironment wrapper and ignore the error? What’s the cause? What’s the risk?

edit: this is the package I’m using for my cache - https://www.npmjs.com/package/node-cache


#2

is it maybe that your collection is growing and since this code basically caches your collection in memory, the memory consumption is growing linear to your collection growth?


#3

Thank you for the reply.

It’s unlikely because that collection has been growing at the same rate since launch and it is very far below 40MB worth of new documents a day. That collection only grows by about 100 documents per day. and it’s a very small document (~8 simple values).

Only once I wrapped the callback in Meteor.bindEnvironment did the memory usage start to climb. I’ve removed it today since the code seemed to work fine without it (even with Kadira displaying an error each time).


#4

it probably was not working before and therefore not allocating memory for the cache at all.

in fact a good way to verify these would be to add the final callbacks to the set and see if it really sets or perhaps throws an error, which might turn out to be the real issue.

all in all, I think it is more likely that the cache related mechanics is causing the growth, not bindenvironment.


#5

Making the callback async, as it fixed the error locally. Deploying now; will report back with results.


#6

It was neither Meteor.bindEnvironment nor the cache. Not using Meteor.bindEnvironment was causing the server to crash and restart, clearing any memory usage. I disabled the cache altogether and it still eats memory at a rate of 40MB a day.

If anyone reads this and has any tips for finding memory leaks… I’d appreciate them. Thanks.