Skip to content

[Fixed] GraphQL Subscriptions: Max Listeners Exceeded Warning #1359

@ayoubyoub

Description

@ayoubyoub

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,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions