From 79aeeea6401e281a1c72def4488c2b2a28e62aa5 Mon Sep 17 00:00:00 2001 From: Nick O'Leary Date: Mon, 13 Jan 2014 11:32:16 +0000 Subject: [PATCH] Handle duplicate PUBREL Fixes #138 If the connection to a broker is lost mid qos 2 flow, there is a window where we have processed the PUBREL, released the message and deleted it from our store, but not sent the PUBCOMP. When the connection is re-established, and the PUBREL is resent by the broker, we assume the message still exists - and hit the error reported. The fix is to check the message is valid before trying to process it. We send the PUBCOMP to complete the flow regardless. --- nodes/core/io/lib/mqtt.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nodes/core/io/lib/mqtt.js b/nodes/core/io/lib/mqtt.js index 1c1e4e498..87356c792 100644 --- a/nodes/core/io/lib/mqtt.js +++ b/nodes/core/io/lib/mqtt.js @@ -130,8 +130,10 @@ MQTTClient.prototype.connect = function(options) { client.on('pubrel',function(packet) { self.lastInbound = (new Date()).getTime() var p = self.inboundMessages[packet.messageId]; - self.emit('message',p.topic,p.payload,p.qos,p.retain); - delete self.inboundMessages[packet.messageId]; + if (p) { + self.emit('message',p.topic,p.payload,p.qos,p.retain); + delete self.inboundMessages[packet.messageId]; + } self.lastOutbound = (new Date()).getTime() self.client.pubcomp(packet); });