From 3431f2406dadb56afb5813a16699706a20288241 Mon Sep 17 00:00:00 2001 From: Luke Policinski Date: Thu, 6 Aug 2020 14:52:54 -0400 Subject: [PATCH] Fixing an issue of max message identifier It is possible to go over the max message identifier which will cause QoS events to stop processing. --- src/paho-mqtt.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/paho-mqtt.js b/src/paho-mqtt.js index 9ca3d37..506b641 100644 --- a/src/paho-mqtt.js +++ b/src/paho-mqtt.js @@ -834,7 +834,7 @@ function onMessageArrived(message) { /* The largest message identifier allowed, may not be larger than 2**16 but * if set smaller reduces the maximum number of outbound messages allowed. */ - ClientImpl.prototype.maxMessageIdentifier = 65536; + ClientImpl.prototype.maxMessageIdentifier = 65535; ClientImpl.prototype.connectOptions = null; ClientImpl.prototype.hostIndex = null; ClientImpl.prototype.onConnected = null; @@ -1187,20 +1187,20 @@ function onMessageArrived(message) { */ ClientImpl.prototype._requires_ack = function (wireMessage) { var messageCount = Object.keys(this._sentMessages).length; - if (messageCount > this.maxMessageIdentifier) + if (messageCount >= this.maxMessageIdentifier) throw Error ("Too many messages:"+messageCount); while(this._sentMessages[this._message_identifier] !== undefined) { this._message_identifier++; + if (this._message_identifier === this.maxMessageIdentifier) { + this._message_identifier = 1; + } } wireMessage.messageIdentifier = this._message_identifier; this._sentMessages[wireMessage.messageIdentifier] = wireMessage; if (wireMessage.type === MESSAGE_TYPE.PUBLISH) { this.store("Sent:", wireMessage); } - if (this._message_identifier === this.maxMessageIdentifier) { - this._message_identifier = 1; - } }; /**