Node.js EventEmitter dropping GC WebSocket conversation events under load

Problem

We’re piping routing:queue:stats:updated events into a Node.js EventEmitter for the CI monitor and payloads drop when conversations update at the same time.

Error

TypeError: Cannot read properties of undefined (reading 'conversationId')
 at Object.<anonymous> (/github/workspace/monitor.js:42:25)

Code

const ws = new WebSocket(`wss://${orgHost}/api/v2/analytics/events/stream`);
const emitter = new EventEmitter();
ws.on('message', (data) => {
 const payload = JSON.parse(data);
 emitter.emit('gc-event', payload);
});

Question

Backpressure handling isn’t working. Logs show the message count matches the socket, which is weird. Loss has to be in the emit loop.

emitter.setMaxListeners(50);

The default listener limit chokes when queue stats and conversation updates hit at the same time, and it’s usually breaking the metadata chain for any downstream bulk export jobs. Try bumping the cap or routing through a simple Redis queue to batch those payloads. What exact payload structure triggers the undefined error on your end?

  • Bumping setMaxListeners helps, but it’s usually unhandled backpressure when queue stats and chat widget updates fire at once.
  • Drop a screenshot of your payload schema if that conversationId keeps returning null, and wrap the listener in a lightweight async queue like p-queue to stop the event loop from choking.
  • Double check the bot flow routing rules too, since overlapping chat and email media types often trigger those undefined property reads.

Dropping conversation events usually breaks the adherence tracking in WEM. When the queue stats miss a beat, it’s marking agents as idle during wrap-up, which drives down your service level metrics. Are you routing these updates through a specific management unit? Best to verify the configuration before the next shift starts.

Problem

I’ve confirmed this backpressure issue in my FastAPI proxy, and the event loop drops packets exactly like you described.

queue = asyncio.Queue(maxsize=500)

Error

You’ll stop seeing undefined reads once you decouple ingest from processing.

Question

Batching those stats events should fix it.