nodejs / help

:sparkles: Need help with Node.js? File an Issue here. :rocket:
1.47k stars 280 forks source link

Node is crashing #4279

Closed mohanrajanna15 closed 3 months ago

mohanrajanna15 commented 11 months ago

Version

16.20.1

Platform

Darwin Rajanna-MacBook-Pro.local 22.2.0 Darwin Kernel Version 22.2.0: Fri Nov 11 02:08:47 PST 2022; root:xnu-8792.61.2~4/RELEASE_X86_64 x86_64

Subsystem

No response

What steps will reproduce the bug?

There is no accurate STR however, our node app uses rabbitmq client to transact certain messages between endpoints.

What we have noticed is when rabbitmq throws an errors where its shutting down a channel due to some errors, we have seen node process running our app gets crashed hence our app gets crashed. I inspected the portion of code and don't see a catch block to report the exception hence the node is crashing with unhandled exception (node:internal/process/task_queues:82:21) . Here is the stacktrace, we need someone to at least let us know how to avoid this as this is hurting our production systems.

node[3588692]: [Client RabbitMQ] client listener AMQPCM disconnected. Error: Connection closed: 541 (INTERNAL-ERROR) with message "INTERNAL_ERROR"
node[3588692]:     at Object.accept (/opt/client/client-premium-20221-patch2_2022.1.12/node_modules/amqplib/lib/connection.js:90:15)
node[3588692]:     at Connection.mainAccept (/opt/client/client-premium-20221-patch2_2022.1.12/node_modules/amqplib/lib/connection.js:63:33)
node[3588692]:     at TLSSocket.go (/opt/client/client-premium-20221-patch2_2022.1.12/node_modules/amqplib/lib/connection.js:486:48)
node[3588692]:     at TLSSocket.emit (node:events:513:28)
node[3588692]:     at emitReadable_ (node:internal/streams/readable:578:12)
node[3588692]:     at processTicksAndRejections (node:internal/process/task_queues:82:21)
node[3588692]: Unrecoverable RabbitMQ error, closing client...
node[3588692]: Critical uncaught exception:  Connection closed: 541 (INTERNAL-ERROR) with message "INTERNAL_ERROR"
node[3588692]: Shutting down client.

How often does it reproduce? Is there a required condition?

Every now and then

What is the expected behavior? Why is that the expected behavior?

Node should not crash

What do you see instead?

Node is crashing.

Additional information

No response

mohanrajanna15 commented 11 months ago

Team, Can anyone please review this and let us know what can we do here.

preveen-stack commented 10 months ago

can you do catch the rabbitmq disconnections and reestablish rabbitmq connection

The below code perhaps can give you some input (not tested)

const amqp = require('amqplib');

const rabbitMQUrl = 'amqp://localhost';

async function setup() {
  try {
    // Connect to RabbitMQ
    const connection = await amqp.connect(rabbitMQUrl);
    const channel = await connection.createChannel();

    // Declare a queue
    const queueName = 'exampleQueue';
    await channel.assertQueue(queueName, { durable: false });

    // Simulate an error (comment this line if you want to see error recovery in action)
    throw new Error('Simulated error');

    // Send a message to the queue
    const message = 'Hello, RabbitMQ!';
    await channel.sendToQueue(queueName, Buffer.from(message));
    console.log(`Sent message: ${message}`);

    // Close the channel and connection
    await channel.close();
    await connection.close();
  } catch (error) {
    // Handle RabbitMQ errors
    console.error('RabbitMQ Error:', error.message);

    // Perform error recovery here
    // For example, you can implement a reconnection strategy

    // Uncomment the following lines to implement a reconnection strategy
    console.log('Reconnecting to RabbitMQ...');
    setTimeout(setup, 5000); // Retry the setup function after a delay
  }
}

// Start the setup function
setup();
github-actions[bot] commented 4 months ago

It seems there has been no activity on this issue for a while, and it is being closed in 30 days. If you believe this issue should remain open, please leave a comment. If you need further assistance or have questions, you can also search for similar issues on Stack Overflow. Make sure to look at the README file for the most updated links.