Skip to content

Commit

Permalink
Merge pull request #498 from johanneswuerbach/error-unacked-on-close
Browse files Browse the repository at this point in the history
Error pending confirmation callbacks on channel close
  • Loading branch information
squaremo committed Apr 10, 2019
2 parents c28c176 + 16439ea commit 773eb92
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
1 change: 0 additions & 1 deletion .npmignore
Expand Up @@ -4,6 +4,5 @@ scratch
# node_modules is ignored anyway
.travis.yml
bin/amqp-rabbitmq-0.9.1.json
bin/generate-defs.js
etc/
coverage/
6 changes: 6 additions & 0 deletions lib/channel.js
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
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -27,7 +27,7 @@
},
"scripts": {
"test": "make test",
"prepublish": "make"
"prepare": "make"
},
"keywords": [
"AMQP",
Expand Down
13 changes: 13 additions & 0 deletions test/channel_api.js
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 773eb92

Please sign in to comment.