mqtt 5.3.4 → 5.3.6

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.4",
4
+ "version": "5.3.6",
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
@@ -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
  }
@@ -850,6 +850,7 @@ export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbac
850
850
  this.log(
851
851
  '!!connectTimeout hit!! Calling _cleanUp with force `true`',
852
852
  )
853
+ this.emit('error', new Error('connack timeout'))
853
854
  this._cleanUp(true)
854
855
  }, this.options.connectTimeout)
855
856
 
@@ -1752,15 +1753,15 @@ export default class MqttClient extends TypedEventEmitter<MqttClientEventCallbac
1752
1753
  })
1753
1754
  }
1754
1755
 
1755
- if (!this.disconnecting) {
1756
+ if (!this.disconnecting && !this.reconnecting) {
1756
1757
  this.log(
1757
- '_cleanUp :: client not disconnecting. Clearing and resetting reconnect.',
1758
+ '_cleanUp :: client not disconnecting/reconnecting. Clearing and resetting reconnect.',
1758
1759
  )
1759
1760
  this._clearReconnect()
1760
1761
  this._setupReconnect()
1761
1762
  }
1762
1763
 
1763
- if (this.pingTimer !== null) {
1764
+ if (this.pingTimer) {
1764
1765
  this.log('_cleanUp :: clearing pingTimer')
1765
1766
  this.pingTimer.clear()
1766
1767
  this.pingTimer = null