Thursday, 8 November 2018

(node:6261) MaxListenersExceededWarning: Possible EventEmitter memory leak detected

I am getting this error on nodejs app: Node version: v8.11.1

(node:6261) MaxListenersExceededWarning: Possible EventEmitter memory leak
detected. 11 wakeup listeners added. Use emitter.setMaxListeners() to increase
limit

I have a very simple code of pushing notification to IOS device using node-apn. The code is working fine, I am receiving push notifications on device as well

var express               = require('express')
  , serverPort            = 6900
  , app                   = express()
  , http                  = require('http')
  , https                 = require('https')
  , fs                    = require('fs')
  , apn                   = require('apn')
;

var server = http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.write('Hello!');
  res.end();
});

server.listen(serverPort, (err) => {

  if(err) { return console.log("Something bad happened", err); }
});

var apnOptions = {

  token: {
  },
  production: false 
};

var apnProvider = new apn.Provider(apnOptions);
var note        = new apn.Notification();

note.expiry     = Math.floor(Date.now() / 1000) + 3600; // Expires 1 hour from now.
note.badge      = 3;
note.sound      = "ping.aiff";
note.alert      = "\uD83D\uDCE7 \u2709 You have a new message";
note.payload    = { 'messageFrom': 'John Appleseed' };
note.topic      = "com.example.test";

apnProvider.send(note, '6A752501A5DAFF9DCSFRE56C5B0E699385CD14B586CEF4B9C5012DDA4').then( (result) => {

  console.log(result); 
});

The issue here is with APN code, because as soon as I comment APN code, I dont face this error anymore. Can anyone have any idea what is wrong with my code? I feel like I have done everything right here but still I am facing this issue.



from (node:6261) MaxListenersExceededWarning: Possible EventEmitter memory leak detected

No comments:

Post a Comment