Skip to content

Commit

Permalink
Error pending confirmation callbacks on channel close
Browse files Browse the repository at this point in the history
Otherwise waitForConfirms never terminates or terminates node
  • Loading branch information
johanneswuerbach committed Mar 27, 2019
1 parent 099673e commit 16439ea
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ function Channel(connection) {
this.on('nack', this.handleConfirm.bind(this, function(cb) {
if (cb) cb(new Error('message nacked'));
}));
this.on('close', function () {
var cb;
while (cb = this.unconfirmed.shift()) {
if (cb) cb(new Error('channel closed'));
}
})
// message frame state machine
this.handleMessage = acceptDeliveryOrReturn;
}
Expand Down
13 changes: 13 additions & 0 deletions test/channel_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -581,4 +581,17 @@ confirmtest('wait for confirms', function(ch) {
return ch.waitForConfirms();
})

confirmtest('works when channel is closed', function(ch) {
for (var i=0; i < 1000; i++) {
ch.publish('', '', Buffer.from('foobar'), {});
}
return ch.close().then(function () {
return ch.waitForConfirms()
}).then(function () {
assert.strictEqual(true, false, 'Wait should have failed.')
}, function (e) {
assert.strictEqual(e.message, 'channel closed')
});
});

});

0 comments on commit 16439ea

Please sign in to comment.