From 97a1f0b0057e16d8359d7d80f659032eb84b8b1b Mon Sep 17 00:00:00 2001 From: "gianluca.casagrande" Date: Mon, 8 Jan 2024 17:59:55 +0100 Subject: [PATCH 1/3] delete already closed client on closeSameClients --- aedes.js | 8 +++++++- package.json | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/aedes.js b/aedes.js index c02d2898..ff28e775 100644 --- a/aedes.js +++ b/aedes.js @@ -168,7 +168,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() } diff --git a/package.json b/package.json index 50b19bc5..bd552956 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aedes", - "version": "0.50.1", + "version": "0.50.2", "description": "Stream-based MQTT broker", "main": "aedes.js", "types": "aedes.d.ts", From a7e03babb4860d4b86063289cb383af9b8347000 Mon Sep 17 00:00:00 2001 From: "gianluca.casagrande" Date: Tue, 9 Jan 2024 08:44:55 +0100 Subject: [PATCH 2/3] version rollback --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index bd552956..50b19bc5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aedes", - "version": "0.50.2", + "version": "0.50.1", "description": "Stream-based MQTT broker", "main": "aedes.js", "types": "aedes.d.ts", From 644ce713667ba2576000998e43e470401daf212a Mon Sep 17 00:00:00 2001 From: "gianluca.casagrande" Date: Tue, 9 Jan 2024 17:32:55 +0100 Subject: [PATCH 3/3] add clear closed clients test --- test/events.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/events.js b/test/events.js index 40191395..cd2137a1 100644 --- a/test/events.js +++ b/test/events.js @@ -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)) +})