question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question - handling connection closure with reason "shutdown"

See original GitHub issue

Hey @cressie176,

I have an application consuming a queue. Currently, when there is a maintenance of our RMQ cluster (and I guess that RMQ node is stopped and replaced or restarted). My application gets "CONNECTION_FORCED - broker forced connection closure with reason 'shutdown'" message and it stops consuming the queue until I manually restart the application. Within the application I initialize its subscription to queue in following way:

const broker = await Broker.create(...);

broker.on("error",
  err => logger.error("RabbitBroker (rascal) - error", err)
);

const subscription = await broker.subscribe(...);
subscription
  .on("message", (message, content, ackOrNack) => {
    ...
  })
  .on("error",
    err => logger.error("Subscription error", err)
  );

During last maintenance, it logged those two messages (emitting an error events for both subscription and broker):

ERROR Subscription error - Error: Connection closed: 320 (CONNECTION-FORCED) with message "CONNECTION_FORCED - broker forced connection closure with reason 'shutdown'"

ERROR RabbitBroker (rascal) - error - Error: Connection closed: 320 (CONNECTION-FORCED) with message "CONNECTION_FORCED - broker forced connection closure with reason 'shutdown'"

When an error event is emitted for broker or subscription is there any chance that it will recover? Can my app detect somehow that connection won’t be restored/rebuild in this case? I am thinking about terminating the application and letting underlying (container) orchestrator to restart it - but I am afraid there could be other error event types where restarting could be harmful.

Thank you for making this awesome library and supporting its users!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:34 (33 by maintainers)

github_iconTop GitHub Comments

1reaction
cressie176commented, Jun 28, 2021

Hi @matej-prokop,

Thanks for the extra debug. It shows that the connection was successfully re-established, but that attempts to borrow channels from the pool never yield a result. You can see the queue growing (1, 2, 3) but never released - available is 0 and borrowed is zero.

It’s possible that there’s a bug somewhere and channel allocation, which is paused while the connection is unavailable, is somehow never resumed when it recovers. It could also be that the channel pool has somehow choked. I’ll see if I can reproduce.

1reaction
matej-prokopcommented, Jun 27, 2021

All my tests were done with rascal 13.0.2 and amqplib 0.7.1 so it must be something else. I will retry with DEBUG=rascal:* and share output here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

RabbitMQ - Root Cause for Broker Forced Connection Closures
When this issue occurs, the corresponding RabbitMQ process restarts and recovers but the corresponding application has to be manually restarted.
Read more >
Restarting of RabbitMQ leads to exception · Issue #856 - GitHub
I thought that it will keep trying to connect to the brocker every 5 seconds and will continue to handle messages when broker...
Read more >
Why do my RabbitMQ channels keep closing? - Stack Overflow
It turns out that the AMQP connection was being closed by the JVM when it ran out of memory. However, for some reason,...
Read more >
4.7. The Mysteries of Connection Close - HTTP - O'Reilly
Connections can close at any time, even in non-error conditions. HTTP applications have to be ready to properly handle unexpected closes. If a...
Read more >
TCP Connection Termination - GeeksforGeeks
In the below Figures illustrate the series of states visited by the server-side and also the Client-side, assuming the client begins connection ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found