I was testing some error scenarios and found unexpected behaviour when using the Connection class' reconnectStrategy.
reconnect doesn't happen if the connection is closed due to "CONNECTION-FORCED"
after a successful reconnect, the 'close' callback isn't invoked
amqp-ts seems to handle closing connections differently in scenario 1 and 2. Scenario 1 works as expected while scenario 2 doesn't reconnect, but leaves consumers hanging as if nothing happened.
By hooking up the 'close' callback, I see that only Scenario 1 results in a isFatalError=true from the dependency amqplib. The 'close' callback also allows me to detect that Scenario 2 doesn't reconnect and results in isFatalError=false.
If Scenario 1 happens, the 'close' callback is only invoked on the first 'close' event. Since I have to handle Scenario 2 manually this unfortunately renders the reconnect feature unuseful for me, since I can't handle the manual reconnects if a successful reconnect has already happened.
Scenario 1: reconnects as expected ✅
amqp-ts connects (successfully) to a rabbit-instance in a 3-node cluster
terminate the rabbitmq instance the client connected to (with kill -9 <PID>)
amqp-ts reconnects
(repeat step 2 and 3)
Setting up a callback on 'close' shows that amqplib's isFatalError returns true.
Scenario 2: reconnect doesn't happen on CONNECTION-FORCED ❌
amqp-ts connects (successfully) to a rabbit-instance in a 3-node cluster
restart the rabbitmq service (Ubuntu) the client connected to (with sudo systemctl restart rabbitmq-server.service)
no reconnect
'close' callback is invoked and consumer is hanging without consuming events
Setting up a callback on 'close' shows that amqplib's isFatalError returns false and error: "Connection closed: 320 (CONNECTION-FORCED) with message "CONNECTION_FORCED - broker forced connection closure with reason 'shutdown'".
Hi and thank you for the project 👍
I was testing some error scenarios and found unexpected behaviour when using the Connection class'
reconnectStrategy
.amqp-ts seems to handle closing connections differently in scenario 1 and 2. Scenario 1 works as expected while scenario 2 doesn't reconnect, but leaves consumers hanging as if nothing happened.
By hooking up the 'close' callback, I see that only Scenario 1 results in a
isFatalError=true
from the dependencyamqplib
. The 'close' callback also allows me to detect that Scenario 2 doesn't reconnect and results inisFatalError=false
.If Scenario 1 happens, the 'close' callback is only invoked on the first 'close' event. Since I have to handle Scenario 2 manually this unfortunately renders the reconnect feature unuseful for me, since I can't handle the manual reconnects if a successful reconnect has already happened.
Scenario 1: reconnects as expected ✅
kill -9 <PID>
)true
.Scenario 2: reconnect doesn't happen on CONNECTION-FORCED ❌
sudo systemctl restart rabbitmq-server.service
)false
and error: "Connection closed: 320 (CONNECTION-FORCED) with message "CONNECTION_FORCED - broker forced connection closure with reason 'shutdown'".Scenario 3: 'close' callback isn't invoked after succesfull reconnect (scenario 1) ❌
kill -9 <PID>
)sudo systemctl restart rabbitmq-server.service
)