Skip to content

Commit

Permalink
fix: delete already closed client on closeSameClients (#929)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Lando <[email protected]>
  • Loading branch information
Gianluca-Casagrande-Stiga and robertsLando authored Jan 12, 2024
1 parent e1ee60c commit f42882c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
8 changes: 7 additions & 1 deletion aedes.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,13 @@ function Aedes (opts) {
const clientId = packet.payload.toString()

if (that.clients[clientId] && serverId !== that.id) {
that.clients[clientId].close(done)
if (that.clients[clientId].closed) {
// remove the client from the list if it is already closed
delete that.clients[clientId]
done()
} else {
that.clients[clientId].close(done)
}
} else {
done()
}
Expand Down
17 changes: 17 additions & 0 deletions test/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,20 @@ test('Test backpressure aedes published function', function (t) {
})
})
})

test('clear closed clients when the same clientId is managed by another broker', function (t) {
t.plan(1)

const clientId = 'closed-client'
const broker = aedes()

// simulate a closed client on the broker
broker.clients[clientId] = { closed: true }

// simulate the creation of the same client on another broker of the cluster
broker.publish({ topic: '$SYS/anotherbroker/new/clients', payload: clientId }, () => {
t.equal(broker.clients[clientId], undefined) // check that the closed client was removed
})

t.teardown(broker.close.bind(broker))
})

0 comments on commit f42882c

Please sign in to comment.