cody-greene / node-rabbitmq-client

RabbitMQ (0-9-1) client library with auto-reconnect & zero dependencies
MIT License
130 stars 9 forks source link

RangeError: The value of "size" is out of range. Facing only on my AWS ECS deployment #61

Closed ayush-zuma closed 3 weeks ago

ayush-zuma commented 3 weeks ago

Hi,

Thank you building this helpful library. It's very easy to work with, and definitely helps take care a lot of boilerplate code.

I have been building a project, and it is working as expected on my local machine, but today i deployed it on AWS ECS and suddenly as soon as the app loads it starts throwing the following error in loop

RangeError [ERR_OUT_OF_RANGE]: The value of "size" is out of range. It must be <= 1GiB. Received 1345270063

Strangely enough, i am using more or less the same boilerplate code for my other project, which is also deployed on AWS ECS but that works normally.

Any ideas what I could be doing wrong here?

export const createConsumer = (routingKey, queueHandler, rabbit, setupDLQ) => {
  const [exchange, key, task] = routingKey.split('.');
  const queueOptions = { durable: true };
  if (setupDLQ) {
    queueOptions.arguments = {
      'x-dead-letter-exchange': `${exchange}-dlx`,
      'x-dead-letter-routing-key': `failed-${key}-dlq`,
      'x-message-ttl': 6000,
      'x-consumer-timeout': 3_600_000,
    };
  }
  const sub = rabbit.createConsumer(
    {
      concurrency: 1,
      queue: `${exchange}-${key}-${task}`,
      queueOptions,
      qos: { prefetchCount: 2 },
      exchanges: [{ exchange, type: 'direct' }],
      queueBindings: [{ exchange, routingKey }],
    },
    async (msg) => {
      await queueHandler(msg, rabbit);
    },
  );

  sub.on('error', async (err) => {});

  return sub;
}

And the error stack is

RangeError [ERR_OUT_OF_RANGE]: The value of "size" is out of range. It must be <= 1GiB. Received 1345270063
 at computeNewHighWaterMark (node:internal/streams/readable:611:11
  at Readable.read (node:internal/streams/readable:659:27)
  at Socket.read (node:net:773:39)
  at Socket._read (/app/node_modules/rabbitmq-client/lib/util.js:84:28)
  at Socket.emit (node:events:531:35)
  at TCP.<anonymous> (node:net:339:12)
cody-greene commented 3 weeks ago

Wow, that's a large message! Try lowering the frameMax option on the connection. It looks like node's socket.read() method has a limit of 1GiB, so I should limit frameMax to 2^30 - 1 bytes. Meanwhile you can set this value yourself. Let me me know if this works for you.

  /** Max size, in bytes, of AMQP data frames. Protocol max is
   * 2^32-1. Actual value is negotiated with the server.
   * @default 4096 */
  frameMax?: number,
const rabbit = new Connection({ 
  frameMax: 10484760, // 10 MiB
})
cody-greene commented 3 weeks ago

Note that this option does not limit your message size. Large messages are split into multiple frames.

ayush-zuma commented 3 weeks ago

@cody-greene I am sorry for wasting your time. It turns out, my docker build was not exposing the node env value correctly, because of which the connection string was passed as undefined. But thank you for your quick response.