aedes 0.51.2 → 0.51.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/aedes.js +7 -3
- package/lib/handlers/subscribe.js +7 -0
- package/package.json +2 -2
- package/test/events.js +8 -6
package/aedes.js
CHANGED
|
@@ -172,7 +172,7 @@ function Aedes (opts) {
|
|
|
172
172
|
if (that.clients[clientId] && serverId !== that.id) {
|
|
173
173
|
if (that.clients[clientId].closed) {
|
|
174
174
|
// remove the client from the list if it is already closed
|
|
175
|
-
|
|
175
|
+
that.deleteClient(clientId)
|
|
176
176
|
done()
|
|
177
177
|
} else {
|
|
178
178
|
that.clients[clientId].close(done)
|
|
@@ -316,8 +316,7 @@ Aedes.prototype._finishRegisterClient = function (client) {
|
|
|
316
316
|
}
|
|
317
317
|
|
|
318
318
|
Aedes.prototype.unregisterClient = function (client) {
|
|
319
|
-
this.
|
|
320
|
-
delete this.clients[client.id]
|
|
319
|
+
this.deleteClient(client.id)
|
|
321
320
|
this.emit('clientDisconnect', client)
|
|
322
321
|
this.publish({
|
|
323
322
|
topic: $SYS_PREFIX + this.id + '/disconnect/clients',
|
|
@@ -325,6 +324,11 @@ Aedes.prototype.unregisterClient = function (client) {
|
|
|
325
324
|
}, noop)
|
|
326
325
|
}
|
|
327
326
|
|
|
327
|
+
Aedes.prototype.deleteClient = function (clientId) {
|
|
328
|
+
this.connectedClients--
|
|
329
|
+
delete this.clients[clientId]
|
|
330
|
+
}
|
|
331
|
+
|
|
328
332
|
function closeClient (client, cb) {
|
|
329
333
|
this.clients[client].close(cb)
|
|
330
334
|
}
|
|
@@ -155,6 +155,13 @@ function addSubs (sub, done) {
|
|
|
155
155
|
func = blockDollarSignTopics(func)
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
+
if (client.closed || client.broker.closed) {
|
|
159
|
+
// a hack, sometimes client.close() or broker.close() happened
|
|
160
|
+
// before authenticate() comes back
|
|
161
|
+
// we don't continue subscription here
|
|
162
|
+
return
|
|
163
|
+
}
|
|
164
|
+
|
|
158
165
|
if (!client.subscriptions[topic]) {
|
|
159
166
|
client.subscriptions[topic] = new Subscription(qos, func, rh, rap, nl)
|
|
160
167
|
broker.subscribe(topic, func, done)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aedes",
|
|
3
|
-
"version": "0.51.
|
|
3
|
+
"version": "0.51.3",
|
|
4
4
|
"description": "Stream-based MQTT broker",
|
|
5
5
|
"main": "aedes.js",
|
|
6
6
|
"types": "aedes.d.ts",
|
|
@@ -133,6 +133,6 @@
|
|
|
133
133
|
"mqtt-packet": "^9.0.0",
|
|
134
134
|
"retimer": "^4.0.0",
|
|
135
135
|
"reusify": "^1.0.4",
|
|
136
|
-
"uuid": "^
|
|
136
|
+
"uuid": "^10.0.0"
|
|
137
137
|
}
|
|
138
138
|
}
|
package/test/events.js
CHANGED
|
@@ -223,18 +223,20 @@ test('Test backpressure aedes published function', function (t) {
|
|
|
223
223
|
})
|
|
224
224
|
|
|
225
225
|
test('clear closed clients when the same clientId is managed by another broker', function (t) {
|
|
226
|
-
t.plan(
|
|
226
|
+
t.plan(2)
|
|
227
227
|
|
|
228
228
|
const clientId = 'closed-client'
|
|
229
|
-
const
|
|
229
|
+
const aedesBroker = aedes()
|
|
230
230
|
|
|
231
231
|
// simulate a closed client on the broker
|
|
232
|
-
|
|
232
|
+
aedesBroker.clients[clientId] = { closed: true, broker: aedesBroker }
|
|
233
|
+
aedesBroker.connectedClients = 1
|
|
233
234
|
|
|
234
235
|
// simulate the creation of the same client on another broker of the cluster
|
|
235
|
-
|
|
236
|
-
t.equal(
|
|
236
|
+
aedesBroker.publish({ topic: '$SYS/anotherbroker/new/clients', payload: clientId }, () => {
|
|
237
|
+
t.equal(aedesBroker.clients[clientId], undefined) // check that the closed client was removed
|
|
238
|
+
t.equal(aedesBroker.connectedClients, 0)
|
|
237
239
|
})
|
|
238
240
|
|
|
239
|
-
t.teardown(
|
|
241
|
+
t.teardown(aedesBroker.close.bind(aedesBroker))
|
|
240
242
|
})
|