Calling send() in loop with 11+ iterations causes memory leak warning #56

Open
clintharris opened this Issue Dec 1, 2011 · 3 comments

Projects

None yet

4 participants

Getting the following when I fire off emails inside a loop with 11+ iterations (i.e., 10 or fewer iterations doesn't generate this warning):

c$ node mailer-test.js
(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace: 
    at SMTPClient.<anonymous> (events.js:133:17)
    at SMTPClientPool.send (/Users/c/dev/mailer-test/node_modules/mailer/lib/node_mailer.js:72:10)
    at dispatchMail (/Users/c/dev/mailer-test/node_modules/mailer/lib/node_mailer.js:112:12)
    at Object.node_mail [as send] (/Users/c/dev/mailer-test/node_modules/mailer/lib/node_mailer.js:159:5)
    at Object.<anonymous> (/Users/c/dev/mailer-test/mailer-test.js:5:10)
    at Module._compile (module.js:425:26)
    at Object..js (module.js:443:10)
    at Module.load (module.js:344:31)
    at Function._load (module.js:303:12)
    at Array.0 (module.js:463:10)

To be clear, everything works (emails are sent)--just reporting the memory leak warning. Maybe a false positive?

Tested with mailer 0.6.7 and node 0.5.7 (darwin) / 0.6.3 (win32) using the following:

var mailer = require('mailer');

for(var i = 0; i < 11; i++) { // Change 11 to 10 and warnings no longer appear
  mailer.send({
      to: 'Some Body <someone@somewhere.com>',
      from : 'Me <me@somewhereelse.com>',
      subject: 'Test '+i,
      body: 'Blah',
      host : "xxx", 
      port : "465",
      ssl: true,
      authentication : "login",
      username : "xxx",
      password : "yyy"
    },
    function(err, result){
      if(err){ console.log(err); }
    }
  );
}

This: http://stackoverflow.com/questions/9768444/possible-eventemitter-memory-leak-detected
gave me a hint as to what was going on, but not sure how to solve this.

polo2ro commented Jan 27, 2017

I got the problem in my unit tests. The warning s fired only for more than 10 new instance of the "transporter" but there is no warning to send more than 10 email with the same transporter. You just need to make sure nodemailer.createTransport() is called once.

The problem is real if you need to send mails with 11 different configurations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment