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

WebSockets are not closed on non zero CONNACK return codes #1718

Closed
lucacasonato opened this issue Jun 5, 2020 · 6 comments
Closed

WebSockets are not closed on non zero CONNACK return codes #1718

lucacasonato opened this issue Jun 5, 2020 · 6 comments
Labels
Status: Completed Nothing further to be done with this issue, it can be closed by the requestor or committer.
Milestone

Comments

@lucacasonato
Copy link

lucacasonato commented Jun 5, 2020

If I send a CONNECT packet with invalid credentials, mosquitto will return a CONNACK packet with this content: 0x20 0x02 0x00 0x05. This is correct, except per the spec the broker has to close the connection after sending a non 0 return code, which mosquitto does not do.

[MQTT-3.2.2-5] If a server sends a CONNACK packet containing a non-zero return code it MUST then close the Network Connection.

@ralight
Copy link
Contributor

ralight commented Jun 9, 2020

This works as expected for me. What version of Mosquitto and libwebsockets do you have?

@lucacasonato
Copy link
Author

I am currently using mosquitto 1.6.9, because that is the latest for the Ubuntu PPA. I'll try 1.6.10 and see if I have better luck with that.

@ralight
Copy link
Contributor

ralight commented Jun 9, 2020

I was expecting you to say 1.4.10 or something equally old, 1.6.9 should be working fine.

@lucacasonato
Copy link
Author

Ok - just checked this again and it seems to be an issue where the client implementation I am using is not correctly listening for socket close. Sorry for the wrong error report.

@lucacasonato
Copy link
Author

So I did even more testing and I have a reproducible example where mosquitto is not disconnecting:

conf file

port 1895
allow_anonymous false
password_file passwd

listener 9012
protocol websockets

passwd file

bob:$6$KzDhoCl4wf6cLF5V$kyskq7nSgQleaw+KEya5pUJ5kukPM2ap9UjOuhYA8YOH6EPru5UflkagdoghQyT11Qz0EQNLJV/GHIVWwPYGmQ==

test code

Paste this in Chrome Developer Tools and see that "close" never gets printed:

(() => {
  const data = new Uint8Array([
    0x10, 0x47, 0x00, 0x06, 0x4d, 0x51, 0x49, 0x73, 0x64, 0x70, 0x03, 0xc2,
    0x00, 0x3c, 0x00, 0x24, 0x65, 0x34, 0x38, 0x36, 0x64, 0x37, 0x39, 0x61,
    0x2d, 0x39, 0x66, 0x38, 0x31, 0x2d, 0x34, 0x31, 0x64, 0x31, 0x2d, 0x62,
    0x61, 0x66, 0x65, 0x2d, 0x30, 0x37, 0x35, 0x36, 0x36, 0x35, 0x30, 0x62,
    0x36, 0x39, 0x33, 0x35, 0x00, 0x03, 0x62, 0x6f, 0x62, 0x00, 0x0e, 0x77,
    0x72, 0x6f, 0x6e, 0x67, 0x5f, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64
  ]);  
  const ws = new WebSocket("ws:https://127.0.0.1:9012/mqtt", "mqtt");
  ws.onopen = () => {
    console.log("open");
    ws.send(data);
  };
  ws.onclose = () => console.log("close");
})();

@lucacasonato lucacasonato reopened this Jun 9, 2020
@ralight
Copy link
Contributor

ralight commented Jul 15, 2020

Thank you for the easy check, I've got round to looking at this and have just pushed a change that fixes it.

@ralight ralight added this to the 1.6.11 milestone Jul 15, 2020
@ralight ralight added the Status: Completed Nothing further to be done with this issue, it can be closed by the requestor or committer. label Jul 15, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Status: Completed Nothing further to be done with this issue, it can be closed by the requestor or committer.
Projects
None yet
Development

No branches or pull requests

2 participants