-
Notifications
You must be signed in to change notification settings - Fork 69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rascal doesn't reconnect when connection with the broker is dropped #232
Comments
Hi @Zoddo. Have you added error handlers as described in the very important section about error handling? |
I added the following code to your example, and the app restarts the connection as expected broker.on('error', (err) => {
console.error({ err })
}); However I'm confused as to why the application doesn't crash without this. The error event documentation still say
I'll continue to investigate |
Oh, I have an I believe you check if an error listener is attached to the broker instance and don't automatically reconnect if none are attached? I confirm explicitly attaching an error listener to the broker instance fix the issue. |
I worked out what's going on. amqplib is catching the error in what it calls it's main accept loop and [re-emitting]((https://github.com/amqp-node/amqplib/blob/bbe579e467866a40ff1c0ae2428c416111340364/lib/connection.js#L429) it as a frame error. This is handled by the socket error code, which expects a socket close due to the connection having been dropped, and does nothing. I'll change Rascal to emit the error event (and schedule the reconnection) from within a setImmediate. This will cause the error bypasses amqplib's main accept loop and bubble up to the process as expected. I've tested locally and it is caught by the |
Hi @Zoddo Rascal@19.0.0 emits the error events via setImmediate. I issued a major release in case there are unintended side effects, but I can't see a reason why there would be. You do need to add the explicit error handlers, when I tested using a global In making the change, I spotted that I had been handling channel close and connection error events incorrectly - the code was shared with the channel close and connection error, and expected an error event. Consequently it threw an exception that was being swallowed by the aforementioned main accept loop. In practice, I'm not sure this mattered though, as connection close and channel close events are only emitted without errors during a client initiated shutdown. |
Description
When the connection with the broker is closed unexpectedly (for example, when the broker is restarted), Rascal never attempts to reconnect to the broker.
Expected Behavior
Rascal try to reconnect to the broker.
Actual Behavior
Rascal log a connection error in debug mode, but never reconnect.
Possible Fix
Steps to Reproduce
DEBUG='rascal:*'
Context
I also tried to explicitly define the
retry
option on the connection, without success.Your Environment
The text was updated successfully, but these errors were encountered: