1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

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.
This commit is contained in:
Nick O'Leary 2014-01-13 11:32:16 +00:00
parent 6b3010f95b
commit 79aeeea640

View File

@ -130,8 +130,10 @@ MQTTClient.prototype.connect = function(options) {
client.on('pubrel',function(packet) { client.on('pubrel',function(packet) {
self.lastInbound = (new Date()).getTime() self.lastInbound = (new Date()).getTime()
var p = self.inboundMessages[packet.messageId]; var p = self.inboundMessages[packet.messageId];
if (p) {
self.emit('message',p.topic,p.payload,p.qos,p.retain); self.emit('message',p.topic,p.payload,p.qos,p.retain);
delete self.inboundMessages[packet.messageId]; delete self.inboundMessages[packet.messageId];
}
self.lastOutbound = (new Date()).getTime() self.lastOutbound = (new Date()).getTime()
self.client.pubcomp(packet); self.client.pubcomp(packet);
}); });