WhatsApp-Clone-Server icon indicating copy to clipboard operation
WhatsApp-Clone-Server copied to clipboard

[Fixed] GraphQL Subscriptions: Max Listeners Exceeded Warning

Open ayoubyoub opened this issue 4 years ago • 1 comments

Hi

When more than 11 subscriptions occur we get the the node warning "MaxListenersExceededWarning: Possible EventEmitter memory leak detected."

The subscription server looks like this:

const pubsub = new PostgresPubSub({
  host: 'localhost',
  port: process.env.DB_PORT ? parseInt(process.env.DB_PORT) : 5432,
  user: 'testuser',
  password: 'testpassword',
  database: 'whatsapp',
});

[Solution] So i found out that you can change the max listeners in the event emitter of the pubsub instance, like so:

const pubsub = new PostgresPubSub({
  host: 'localhost',
  port: process.env.DB_PORT ? parseInt(process.env.DB_PORT) : 5432,
  user: 'testuser',
  password: 'testpassword',
  database: 'whatsapp',
});

pubsub.ee.setMaxListeners(0); // raise max listeners in event emitter, 0 mean that is limited

Thanks for sharing. Best regards,

ayoubyoub avatar Apr 03 '20 21:04 ayoubyoub

mmm maybe it's worth adding a note about running pub/sub in a separate process/engine?

Urigo avatar May 15 '20 17:05 Urigo