Skip to content

clarification or documentation about channel vs connection events #780

Open
@soryy708

Description

@soryy708

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:

  1. Given
    connection.on('error', ...) and connection.on('close', ...)
    (and no observers on channel)

    Making a "soft" error (as defined by RabbitMQ docs) triggers both connection.on('error', ...) and connection.on('close', ...)

  2. Given
    connection.on('error', ...), connection.on('close', ...), and channel.on('error', ...)

    Making a "soft" error triggers channel.on('error', ...), but neither connection.on('error', ...) or connection.on('close', ...)

  3. Given
    connection.on('error', ...), connection.on('close', ...), and channel.on('close', ...)

    Making a "soft" error triggers connection.on('error', ...), channel.on('close', ...), and connection.on('close', ...)

  4. Given
    connection.on('error', ...), connection.on('close', ...), channel.on('error', ...), and channel.on('close', ...)

    Making a "soft" error triggers channel.on('error', ...), channel.on('close', ...), but neither connection.on('error', ...) or connection.on('close', ...)

In tabular form:

image


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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions