Skip to content

Commit

Permalink
fix: delete will from persistence on disconnect (#957)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Lando <[email protected]>
  • Loading branch information
bmeverett and robertsLando authored Jun 7, 2024
1 parent 1bbff52 commit a26b90b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,14 @@ Client.prototype.close = function (done) {
}, noop)
}
})
} else if (will) {
// delete the persisted will even on clean disconnect https://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc385349232
that.broker.persistence.delWill({
id: that.id,
brokerId: that.broker.id
}, noop)
}

that.will = null // this function might be called twice
that._will = null

Expand Down
23 changes: 23 additions & 0 deletions test/will.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,29 @@ test('does not deliver will when client sends a DISCONNECT', function (t) {
})
})

test('deletes from persistence on DISCONNECT', function (t) {
t.plan(2)

const opts = {
clientId: 'abcde'
}
const broker = aedes()
t.teardown(broker.close.bind(broker))

const s = noError(willConnect(setup(broker), opts, function () {
s.inStream.end({
cmd: 'disconnect'
})
}), t)

s.broker.persistence.getWill({
id: opts.clientId
}, function (err, packet) {
t.error(err, 'no error')
t.notOk(packet)
})
})

test('does not store multiple will with same clientid', function (t) {
t.plan(4)

Expand Down

0 comments on commit a26b90b

Please sign in to comment.