Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jbaramidze opened this issue Mar 26, 2021 · 2 comments
Open

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

jbaramidze opened this issue Mar 26, 2021 · 2 comments
Labels

Comments

@jbaramidze
Copy link

jbaramidze commented Mar 26, 2021

System Information

  • Aedes: 0.44.0
  • NodeJS: 14.15.4
  • OS: macOS 10.15.7 / Darwin 19.6.0
  • Arch: x86_64

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

To Reproduce

  • Launch Aedes broker with aedes-persistence-redis persistence layer. I have used mqtt-cli package for it, with the following config:
module.exports = {
  protos: ['tcp', 'ws'],
  host: '127.0.0.1',
  wsPort: 6423,
  brokerId: 'aedes-cli',
  persistence: {
    name: 'redis',
    options: {
	    url: 'redis://127.0.0.1'
    }
  },
  key: null,
  cert: null,
  rejectUnauthorized: true,
  verbose: false,
  veryVerbose: false,
  noPretty: false
}
  • Connect with a client C1 (non-clean session), and send message to any topic with {retain: true, qos: 2}
  • Disconnect C1
  • Connect with a client C2 (non-clean session), and subscribe to a topic used above with {qos: 2}
  • Aedes crashes inside aedes-persistence-redis with error ERROR: unknown key

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 jbaramidze added the bug label Mar 26, 2021
@jbaramidze jbaramidze changed the title [bug] [bug] Crash when sending retained message with QoS = 2 Mar 26, 2021
@jbaramidze
Copy link
Author

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
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants