diff --git a/lib/handlers/pubrec.js b/lib/handlers/pubrec.js index 62365889..5c914dd6 100644 --- a/lib/handlers/pubrec.js +++ b/lib/handlers/pubrec.js @@ -20,12 +20,10 @@ function handlePubrec (client, packet, done) { function reply (err) { if (err) { - // TODO is this ok? - client._onError(err) - return + done(err) + } else { + write(client, pubrel, done) } - - write(client, pubrel, done) } } diff --git a/test/qos2.js b/test/qos2.js index 119a54cc..64e23628 100644 --- a/test/qos2.js +++ b/test/qos2.js @@ -143,6 +143,23 @@ test('publish QoS 2 throws error on write', function (t) { }) }) +test('pubrec handler calls done when outgoingUpdate fails (clean=false)', function (t) { + t.plan(1) + + const s = connect(setup(), { clean: false }) + t.tearDown(s.broker.close.bind(s.broker)) + + var handle = require('../lib/handlers/pubrec.js') + + s.broker.persistence.outgoingUpdate = function (client, pubrel, done) { + done(Error('throws error')) + } + + handle(s.client, { messageId: 42 }, function done () { + t.pass('calls done on error') + }) +}) + test('client.publish with clean=true subscribption QoS 2', function (t) { t.plan(8)