amqp-node / amqplib

AMQP 0-9-1 library and client for Node.JS
https://amqp-node.github.io/amqplib/
Other
3.69k stars 474 forks source link

CPU intensive controller prevents AMQP connection from receiving heartbeat, hence connections gets closed. #750

Closed ticmaisdev closed 9 months ago

ticmaisdev commented 9 months ago

I've reported this issue on NestJS, so here's the link for reference (includes minimum reproduction code):

https://github.com/nestjs/nest/issues/13040

cressie176 commented 9 months ago

Hi @ticmaidev

This is a consequence / limitation of the Node.js architecture. If you have a long running synchronous task, or you flood the event loop with a high number of asynchronous ones, new tasks may not be executed for quite some time.

In the case of amqplib, this means that it may neither be able to send nor receive heartbeats, and may either close the connection, or have it closed by the broker.

You options are to

  1. Disable heartbeats (which must currently be done on the broker and client), instead relying on tcp keepalive
  2. Move the CPU intensive work to a background process see here and here
  3. Throttle the workload
  4. Scale your services to meet workload
ticmaisdev commented 9 months ago

THANK YOU