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

Fix bug while client subscribing to an Array of topics. #240

Merged
merged 6 commits into from
Jun 3, 2019

Conversation

seeLuck
Copy link
Contributor

@seeLuck seeLuck commented May 29, 2019

1.fix bug while client(MQTT.js) subscribing to an Array of topics. I am curious the original line use only subscriptions[0] in if condition that would ignore the rest topics in an Array.

-2.fix bug while negating a subscription. The original logic is setting sub to null that will cause series problem. e.g: to negate multi topics and to persistent negated topics (which QoS is still 0 in storage).


I retract #2 to pass test case with bugs I mentioned. Maybe you can change this part while you have time :)


I fixed negated topics persistence bug in the third commit.

Multi topics negating bug is still there.

instance.authorizeSubscribe = function (client, sub, callback) {
  if (sub.topic === 'aaaa') {
    sub = null
  }
  if (sub.topic === 'bbbb') { //bug here
    sub = null
  }
  callback(null, sub)
}

I have tried to fix it but it seems to be related several parts and cannot pass test case.

I am not sure whether this is a graceful solution but it can fix bugs of my project for now.

Copy link
Collaborator

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding a unit test?

@seeLuck
Copy link
Contributor Author

seeLuck commented May 30, 2019

Would you mind adding a unit test?

Done.

I noticed an example of 'negate multiple subscriptions' in unit test, code like

instance.authorizeSubscribe = function (client, sub, callback) {
  if (sub.topic === 'aaaa') {
       setTimeout(function () {
        cb(null, null)
      }, 100)
  }
  if (sub.topic === 'bbbb') { // is ok
       setTimeout(function () {
        cb(null, null)
      }, 50)
  }
  callback(null, sub)
}

to avoide the bug I mentioned before. However it looks a little bit strange to avoide them callback at the same time, I left this part in the original logic and only fixed bug about multi topics persistence.

Copy link
Collaborator

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mcollina mcollina merged commit 90c7f22 into moscajs:master Jun 3, 2019
@gnought gnought added the bug label Aug 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants