njoubert / node-groupme

A GroupMe API Module for NodeJS, downloaded over 9000 times on npmjs.com
zlib License
29 stars 21 forks source link

Memory leak, somewhere on Stateless #1

Open ghostbar opened 11 years ago

ghostbar commented 11 years ago

Hi Niels,

I have been using this for quite some time (like one month) and started to have memory leaks. Some times it completed the task (specially at the beginning) but finally there was a huge memory leak that made my app that uses top 73MB go to +1GB on RAM if launched to Stateless.Messages.Create in parallel.

This is the prototype I was using to launch this. I know the way the prototype is structured is not the issue because now I'm doing the request by myself with request in that very same prototype, just changed groupme with a request call.

SMSController.prototype.sendMessage = function(id, message, callback) {
  var self = this,
       gm = require('groupme').Stateless;

  if (id == null || id === '') {
    self.app.log.error("sms/ctrl#sendMessage: there's no id for sending the message");
    return callback(new Error("There's no ID for sending the message"));
  }

  self.app.log.debug({
       data: {
         id: id,
         message: message
       }
     }, "sms/ctrl: sending message");

  if (message.source_guid == null) {
    message['source_guid'] = 'supposedlyanuniqueidentifier';
  }

  return gm.Messages.create(this.app.vars.groupme.token, id, { message: message }, function(err, response) {
    if (err) {
      self.app.log.error({ data: err }, "sms/ctrl#sendMessage: ");
      return callback(err);
    }
    self.app.log.debug(message, "sms/ctrl: message sent");
    return callback(null);
}

FWIW: node v0.10.17. Tested on MacOS X and Linux.

Kind regards.

njoubert commented 11 years ago

Hi Jose! First of all - AWESOME! I'm happy that people are getting mileage out of my code! What are you using this for?

Thanks for the bugfix, I'll look into this at the end of this week - I'm a bit swamped with other work at the moment but I'll see if I can fix this issue as soon as possible.

ghostbar commented 11 years ago

I can't tell yet. I had to write my own requests instead (we are just using the create Message, so it was easy) because this was killing our server :(