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.
pull/139/head
Nick O'Leary 2014-01-13 11:32:16 +00:00
parent 6b3010f95b
commit 79aeeea640
1 changed files with 4 additions and 2 deletions

View File

@ -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);
});