moscajs / aedes-persistence-redis

Aedes persistence, backed by redis
MIT License
21 stars 23 forks source link

[bug] Crash when sending retained message with QoS = 2 #90

Open jbaramidze opened 3 years ago

jbaramidze commented 3 years ago

System Information

Describe the bug aedes-persistence-redis crashes when trying to send retained message of QoS=2

To Reproduce

Expected behavior Should not crash

Additional context After debugging a little, it seems that it crashes when it's trying to send PubRel packet of the retained message. Aedes invokes RedisPersistence.prototype.outgoingUpdate, which calls augmentWithBrokerData. Inside this function, var key = that.messageIdCache.get(messageIdKey) returns undefined, which causes the crash

jbaramidze commented 3 years ago

To help with reproducing, client codes: C1:

import mqtt from "mqtt";
const LOCAL_URL = "ws://localhost:6423/mqtt";
var client = mqtt.connect(LOCAL_URL, {clientId: `3:someString`, username: "3", clean: false})
client.on('connect', function (pack) {
    client.publish(`broadcast/5`, `HELLO ${process.argv[2]}`, {retain: true, qos: 2});
});

C2:

import mqtt from "mqtt";
const LOCAL_URL = "ws://localhost:6423/mqtt";
var client = mqtt.connect(LOCAL_URL, {clientId: `2:someString`, username: "2", clean: false})
client.on('connect', function (pack) {
    client.subscribe(`broadcast/5`, {qos: 2}, function (err, s) {
        console.log("Error on subscribe: ", err);
    });
});
robertsLando commented 3 years ago

@jbaramidze Are you able to submit a PR to fix the issue? It seems you have found the line causing the bug