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

Clients can't connect using MQTT 5.0 #3304

Closed
eisaev opened this issue Mar 11, 2020 · 4 comments
Closed

Clients can't connect using MQTT 5.0 #3304

eisaev opened this issue Mar 11, 2020 · 4 comments
Assignees
Labels
Milestone

Comments

@eisaev
Copy link

eisaev commented Mar 11, 2020

Environment

  • OS: Ubuntu 16.04.6 LTS
  • Erlang/OTP: 22.2.7
  • EMQ: 4.0.4

Description

When I try to connect to EMQX using mosqitto client using MQTT v5, I get an error:

$ mosquitto_sub -d -V mqttv5 -h 192.168.0.1 -p 1883 -t test
Client (null) sending CONNECT
Error: A network protocol error occurred when communicating with the broker.
$ mosquitto_pub -d -V mqttv5 -h 192.168.0.1 -p 1883 -t test -m test_message
Client (null) sending CONNECT
Error: A network protocol error occurred when communicating with the broker.

When using versions 3.1 and 3.1.1, the issue is not observed:

$ mosquitto_pub -d -V mqttv311 -h 192.168.0.1 -p 1883 -t test -m test_message
Client mosq-D8n0wzeaIZCgceT2lw sending CONNECT
Client mosq-D8n0wzeaIZCgceT2lw received CONNACK (0)
Client mosq-D8n0wzeaIZCgceT2lw sending PUBLISH (d0, q0, r0, m1, 'test', ... (12 bytes))
Client mosq-D8n0wzeaIZCgceT2lw sending DISCONNECT

I use mosqitto client version 1.6.9:

$ mosquitto_pub --help | grep -m 1 version
mosquitto_pub version 1.6.9 running on libmosquitto 1.6.9.
$ mosquitto_sub --help | grep -m 1 version
mosquitto_sub version 1.6.9 running on libmosquitto 1.6.9.

The issue is reproduced on the default EMQX configuration as well.

@eisaev
Copy link
Author

eisaev commented Mar 11, 2020

Mosquitto client throws an error because EMQX server passes the value of Maximum QoS property (0x24) equal to 2. According to the MQTT 5.0 Protocol specification, this property must be omitted when set to 2.
https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901084

Followed by a Byte with a value of either 0 or 1. It is a Protocol Error to include Maximum QoS more than once, or to have a value other than 0 or 1. If the Maximum QoS is absent, the Client uses a Maximum QoS of 2.

@eisaev
Copy link
Author

eisaev commented Mar 11, 2020

I fixed it locally like this:

diff --git a/src/emqx_channel.erl b/src/emqx_channel.erl
index 1535924..7df3134 100644
--- a/src/emqx_channel.erl
+++ b/src/emqx_channel.erl
@@ -1150,7 +1150,7 @@ enrich_connack_caps(AckProps, #channel{conninfo   = #{proto_ver := ?MQTT_PROTO_V
       shared_subscription   := Shared,
       wildcard_subscription := Wildcard
      } = emqx_mqtt_caps:get_caps(Zone),
-    AckProps#{'Maximum-QoS'         => MaxQoS,
+    AckProps#{'Maximum-QoS' => case MaxQoS < 2 of true -> MaxQoS; false -> undefined end,
               'Retain-Available'    => flag(Retain),
               'Maximum-Packet-Size' => MaxPktSize,
               'Topic-Alias-Maximum' => MaxAlias,

@tigercl
Copy link
Member

tigercl commented Mar 12, 2020

@eisaev Thanks for your feedback, we will fix this issue as soon as possible.

@HJianBo
Copy link
Member

HJianBo commented Mar 17, 2020

Hi @eisaev We have released v4.0.5, you can try it later

@HJianBo HJianBo closed this as completed Mar 17, 2020
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

3 participants