Description
From experimenting with [email protected]
I noticed some undocumented behavior observing channel vs connection events. I don't know if I can rely on this behavior remaining consistent in future patch versions of amqplib
, because it's currently undocumented.
It appears that observing channel.on('error', ...)
changes the behavior of connection.on('error', ...)
, which also interacts with channel.on('close', ...)
/connection.on('close', ...)
.
If this is an implementation detail, I'd like clarification in this issue. If it's intended as stable behavior, I believe this should be documented in the amqplib docs.
Observations:
-
Given
connection.on('error', ...)
andconnection.on('close', ...)
(and no observers on channel)Making a "soft" error (as defined by RabbitMQ docs) triggers both
connection.on('error', ...)
andconnection.on('close', ...)
-
Given
connection.on('error', ...)
,connection.on('close', ...)
, andchannel.on('error', ...)
Making a "soft" error triggers
channel.on('error', ...)
, but neitherconnection.on('error', ...)
orconnection.on('close', ...)
-
Given
connection.on('error', ...)
,connection.on('close', ...)
, andchannel.on('close', ...)
Making a "soft" error triggers
connection.on('error', ...)
,channel.on('close', ...)
, andconnection.on('close', ...)
-
Given
connection.on('error', ...)
,connection.on('close', ...)
,channel.on('error', ...)
, andchannel.on('close', ...)
Making a "soft" error triggers
channel.on('error', ...)
,channel.on('close', ...)
, but neitherconnection.on('error', ...)
orconnection.on('close', ...)
In tabular form:
This undocumented nuance is a problem in the following example situation:
Suppose the user has:
connection.on('error', logConnectionError)
connection.on('close', reconnectAndAcquireChannel)
So when a "soft" error occurs, it's logged, the connection is closed, and re-acquired. The system self-heals.
Later the user wants more granular logging, so the user adds also:
channel.on('error', logChannelError)
Now when a "soft" error occurs, it's logged, the channel closes, but the connection remains open. Re-acquire isn't run, so the system is in a pathologic state.