WhatsApp-Clone-Server
WhatsApp-Clone-Server copied to clipboard
[Fixed] GraphQL Subscriptions: Max Listeners Exceeded Warning
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,
mmm maybe it's worth adding a note about running pub/sub in a separate process/engine?