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

packet event still emitted after parse error #14

Closed
jdiamond opened this issue Sep 3, 2016 · 2 comments
Closed

packet event still emitted after parse error #14

jdiamond opened this issue Sep 3, 2016 · 2 comments

Comments

@jdiamond
Copy link
Contributor

jdiamond commented Sep 3, 2016

I have a custom broker using mqtt-connection that crashed today because it received a packet that generated a "wrong subscribe header" error.

I think this is what happened:

  • mqtt-packet tried to parse the packet, emitted an error event, then emitted a packet event.
  • mqtt-connection forwarded the error event to me and converted the packet event into a subscribe event.
  • Since the whole packet wasn't parsed, the subscriptions property was undefined. That's where my broker crashed.

IMO, Parser.parse() should skip emitting the packet event as soon as it encounters an error because it seems strange for me to have to validate the packet that mqtt-packet already determined was invalid.

Since the MQTT spec says connections should be closed on protocol violations, maybe Parser.parse() should stop parsing completely when it encounters an error in case there are more packets in the buffer. This would stop mqtt-connection from continuing to emit packets that shouldn't be processed.

If you agree, I can send a PR but I think this is a backwards incompatible change to the API so would require a major bump.

@mcollina
Copy link
Member

mcollina commented Sep 4, 2016

I think that is a bug, both here (it should emit more parse events) and in mqtt-connection (it should close the connection on a parse error). Would you mind to send a couple of PRs?

@robertsLando
Copy link
Member

Fixed by #15

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

No branches or pull requests

3 participants