aedes 0.51.1 → 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/client.js +7 -0
- package/lib/handlers/subscribe.js +7 -0
- package/package.json +5 -5
- package/test/events.js +8 -6
- package/test/will.js +23 -0
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
|
}
|
package/lib/client.js
CHANGED
|
@@ -313,7 +313,14 @@ Client.prototype.close = function (done) {
|
|
|
313
313
|
}, noop)
|
|
314
314
|
}
|
|
315
315
|
})
|
|
316
|
+
} else if (will) {
|
|
317
|
+
// 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
|
|
318
|
+
that.broker.persistence.delWill({
|
|
319
|
+
id: that.id,
|
|
320
|
+
brokerId: that.broker.id
|
|
321
|
+
}, noop)
|
|
316
322
|
}
|
|
323
|
+
|
|
317
324
|
that.will = null // this function might be called twice
|
|
318
325
|
that._will = null
|
|
319
326
|
|
|
@@ -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",
|
|
@@ -108,7 +108,7 @@
|
|
|
108
108
|
"concat-stream": "^2.0.0",
|
|
109
109
|
"duplexify": "^4.1.2",
|
|
110
110
|
"license-checker": "^25.0.1",
|
|
111
|
-
"markdownlint-cli": "^0.
|
|
111
|
+
"markdownlint-cli": "^0.41.0",
|
|
112
112
|
"mqtt": "^5.3.5",
|
|
113
113
|
"mqtt-connection": "^4.1.0",
|
|
114
114
|
"pre-commit": "^1.2.2",
|
|
@@ -117,7 +117,7 @@
|
|
|
117
117
|
"snazzy": "^9.0.0",
|
|
118
118
|
"standard": "^17.1.0",
|
|
119
119
|
"tap": "^16.3.10",
|
|
120
|
-
"tsd": "^0.
|
|
120
|
+
"tsd": "^0.31.0",
|
|
121
121
|
"typescript": "^5.3.3",
|
|
122
122
|
"websocket-stream": "^5.5.2"
|
|
123
123
|
},
|
|
@@ -129,10 +129,10 @@
|
|
|
129
129
|
"fastparallel": "^2.4.1",
|
|
130
130
|
"fastseries": "^2.0.0",
|
|
131
131
|
"hyperid": "^3.2.0",
|
|
132
|
-
"mqemitter": "^
|
|
132
|
+
"mqemitter": "^6.0.0",
|
|
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
|
})
|
package/test/will.js
CHANGED
|
@@ -420,6 +420,29 @@ test('does not deliver will when client sends a DISCONNECT', function (t) {
|
|
|
420
420
|
})
|
|
421
421
|
})
|
|
422
422
|
|
|
423
|
+
test('deletes from persistence on DISCONNECT', function (t) {
|
|
424
|
+
t.plan(2)
|
|
425
|
+
|
|
426
|
+
const opts = {
|
|
427
|
+
clientId: 'abcde'
|
|
428
|
+
}
|
|
429
|
+
const broker = aedes()
|
|
430
|
+
t.teardown(broker.close.bind(broker))
|
|
431
|
+
|
|
432
|
+
const s = noError(willConnect(setup(broker), opts, function () {
|
|
433
|
+
s.inStream.end({
|
|
434
|
+
cmd: 'disconnect'
|
|
435
|
+
})
|
|
436
|
+
}), t)
|
|
437
|
+
|
|
438
|
+
s.broker.persistence.getWill({
|
|
439
|
+
id: opts.clientId
|
|
440
|
+
}, function (err, packet) {
|
|
441
|
+
t.error(err, 'no error')
|
|
442
|
+
t.notOk(packet)
|
|
443
|
+
})
|
|
444
|
+
})
|
|
445
|
+
|
|
423
446
|
test('does not store multiple will with same clientid', function (t) {
|
|
424
447
|
t.plan(4)
|
|
425
448
|
|