mqtt 5.3.3 → 5.3.5

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mqtt",
3
3
  "description": "A library for the MQTT protocol",
4
- "version": "5.3.3",
4
+ "version": "5.3.5",
5
5
  "contributors": [
6
6
  "Adam Rudd <adamvrr@gmail.com>",
7
7
  "Matteo Collina <matteo.collina@gmail.com> (https://github.com/mcollina)",
@@ -113,7 +113,7 @@
113
113
  "commist": "^3.2.0",
114
114
  "concat-stream": "^2.0.0",
115
115
  "debug": "^4.3.4",
116
- "help-me": "^4.2.0",
116
+ "help-me": "^5.0.0",
117
117
  "lru-cache": "^10.0.1",
118
118
  "minimist": "^1.2.8",
119
119
  "mqtt": "^5.2.0",
@@ -21,14 +21,7 @@ export default class PingTimer {
21
21
  constructor(keepalive: number, checkPing: () => void) {
22
22
  this.keepalive = keepalive * 1000
23
23
  this.checkPing = checkPing
24
- this.setup()
25
- }
26
-
27
- private setup() {
28
- this.timer = this._setTimeout(() => {
29
- this.checkPing()
30
- this.reschedule()
31
- }, this.keepalive)
24
+ this.reschedule()
32
25
  }
33
26
 
34
27
  clear() {
@@ -40,6 +33,13 @@ export default class PingTimer {
40
33
 
41
34
  reschedule() {
42
35
  this.clear()
43
- this.setup()
36
+ this.timer = this._setTimeout(() => {
37
+ this.checkPing()
38
+ // prevent possible race condition where the timer is destroyed on _cleauUp
39
+ // and recreated here
40
+ if (this.timer) {
41
+ this.reschedule()
42
+ }
43
+ }, this.keepalive)
44
44
  }
45
45
  }
package/src/lib/client.ts CHANGED
@@ -248,7 +248,7 @@ export interface IClientOptions extends ISecureClientOptions {
248
248
  */
249
249
  clean?: boolean
250
250
  /**
251
- * 10 seconds, set to 0 to disable
251
+ * 60 seconds, set to 0 to disable
252
252
  */
253
253
  keepalive?: number
254
254
  /**
@@ -639,7 +639,7 @@ export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbac
639
639
  clearTimeout(this.connackTimer)
640
640
 
641
641
  this.log('close :: clearing ping timer')
642
- if (this.pingTimer !== null) {
642
+ if (this.pingTimer) {
643
643
  this.pingTimer.clear()
644
644
  this.pingTimer = null
645
645
  }
@@ -1752,15 +1752,15 @@ export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbac
1752
1752
  })
1753
1753
  }
1754
1754
 
1755
- if (!this.disconnecting) {
1755
+ if (!this.disconnecting && !this.reconnecting) {
1756
1756
  this.log(
1757
- '_cleanUp :: client not disconnecting. Clearing and resetting reconnect.',
1757
+ '_cleanUp :: client not disconnecting/reconnecting. Clearing and resetting reconnect.',
1758
1758
  )
1759
1759
  this._clearReconnect()
1760
1760
  this._setupReconnect()
1761
1761
  }
1762
1762
 
1763
- if (this.pingTimer !== null) {
1763
+ if (this.pingTimer) {
1764
1764
  this.log('_cleanUp :: clearing pingTimer')
1765
1765
  this.pingTimer.clear()
1766
1766
  this.pingTimer = null
@@ -2260,9 +2260,9 @@ export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbac
2260
2260
  break
2261
2261
  }
2262
2262
  }
2263
+ this.removeListener('close', remove)
2263
2264
  if (allProcessed) {
2264
2265
  clearStoreProcessing()
2265
- this.removeListener('close', remove)
2266
2266
  this._invokeAllStoreProcessingQueue()
2267
2267
  this.emit('connect', packet)
2268
2268
  } else {