Skip to content

Commit

Permalink
Merge 27d206a into 6b0c8fc
Browse files Browse the repository at this point in the history
  • Loading branch information
robertsLando committed Jan 15, 2020
2 parents 6b0c8fc + 27d206a commit 0df9834
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/handlers/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,17 @@ function restoreSubs (arg, done) {
function storeWill (arg, done) {
var client = this.client
client.will = client._will
if (client.will) {
client.broker.persistence.putWill(
client,
client.will,
done)
return
}
done()
// delete any existing will messages from persistence
client.broker.persistence.delWill(client, function () {
if (client.will) {
client.broker.persistence.putWill(
client,
client.will,
done)
} else {
done()
}
})
}

function registerClient (arg, done) {
Expand Down
27 changes: 27 additions & 0 deletions test/will.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,3 +320,30 @@ test('does not deliver will when client sends a DISCONNECT', function (t) {

broker.on('closed', t.end.bind(t))
})

test('does not store multiple will with same clientid', function (t) {
var opts = { clientId: 'abcde' }

var broker = aedes()
var s = willConnect(setup(broker), opts, function () {
// gracefully close client so no will is sent
s.inStream.end({
cmd: 'disconnect'
})

// reconnect same client with will
s = willConnect(setup(broker), opts, function () {
// check that there are not 2 will messages for the same clientid
s.broker.persistence.delWill({ id: opts.clientId }, function (err, packet) {
t.error(err, 'no error')
t.equal(packet.clientId, opts.clientId, 'will packet found')
s.broker.persistence.delWill({ id: opts.clientId }, function (err, packet) {
t.error(err, 'no error')
t.equal(!!packet, false, 'no duplicated packets')
})
})
})
})

broker.on('closed', t.end.bind(t))
})

0 comments on commit 0df9834

Please sign in to comment.