From ac94edc5a52f0fccd80d8f9696f8869aa7962cda Mon Sep 17 00:00:00 2001 From: David Wittman Date: Mon, 20 Jul 2020 15:29:52 -0500 Subject: [PATCH] Bubble channel failures up to the connection Send channel failures up to the connection so that they can be handled appropriately. Previously, errors on channels caused silent failures which could result in queues being unable to receive messages without any indication of failure, such as described in https://github.com/arobson/rabbot/issues/155. This approach is a bit naive in that it causes the whole connection to fail when an a single channel fails, but I don't think the abstractions in this library allow for the user to respond to channel-level events. In my case, this type of failure occurred any time my consumers lost their connection to the RabbitMQ cluster and tried to send an ack for an old delivery tag to a different RMQ node in the cluster (i.e. queue is re-established on new node and batch acks send after reconnecting). This would result in the following error in amqplib: Error: Channel closed by server: 406 (PRECONDITION-FAILED) with message "PRECONDITION_FAILED - unknown delivery tag 42" But from the perspective of foo-foo-mq/rabbot, everything was fine. With these changes in place, I can at least listen for a `failed` event on the broker and respond appropriately. --- src/connectionFsm.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/connectionFsm.js b/src/connectionFsm.js index 0045e8c..8665d7e 100644 --- a/src/connectionFsm.js +++ b/src/connectionFsm.js @@ -68,6 +68,10 @@ const Connection = function (options, connectionFn, channelFn) { channel.on('return', (raw) => { this.emit('return', raw); }); + channel.on('failed', () => { + this.transition('failed'); + this.handle('failed'); + }); }); } else { return Promise.resolve(channel);