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

On_disconnect Callback Returns ReasonCode=7 with EMQX over WebSockets in Paho MQTT" #803

Open
matiasAS opened this issue Jan 18, 2024 · 6 comments
Labels
Status: Available No one has claimed responsibility for resolving this issue.

Comments

@matiasAS
Copy link

Environment
Python version: 3.10.13
Library version: 1.6.1
Operating system (including version): Alpine Linux 3.18.5
MQTT server (name, version, configuration, hosting details): EMQX 5.4.1 hosted on an AWS EC2 instance. The server is set up with app Dokku configured with ports:add https:8443:8083. It also has SSL with the Dokku LetsEncrypt plugin. The domain is broker.mydomain.com and it's on Cloudflare with the proxy activated. MQTT protocol version 5, transport=websockets, client.tls_set(tls_version=ssl.PROTOCOL_TLSv1_2).
Question
I am encountering an issue where I receive a reasonCode=7 in the on_disconnect callback when using the Paho MQTT Python client. This happens under the following conditions:

Using MQTT protocol version 5
The connection is over WebSockets (transport=websockets)
TLS is configured with client.tls_set(tls_version=ssl.PROTOCOL_TLSv1_2)
The issue arises when the client disconnects from the EMQX broker. I would like to understand the possible causes of this reasonCode=7 and any solutions or workarounds that might be available. This reasonCode is not clearly defined in the MQTT 5.0 specification or in the Paho MQTT documentation, so any insights into its meaning and how to address the underlying issue would be greatly appreciated.

Regards
Matias

@github-actions github-actions bot added the Status: Available No one has claimed responsibility for resolving this issue. label Jan 18, 2024
@MattBrittan
Copy link
Contributor

reason code 7 = "MQTT_ERR_CONN_LOST"; this is returned when the network connection drops.

As you have not provided any sample code, logs or much detail over when this happens ("when the client disconnects" - do you mean that you are calling disconnect()?) . Suggestions (I assume you have tested the connection using another client, such as MQTTX?), check the broker logs and, if that does not help, the client logs. There are a number of things that could cause this issue (some from the MQTT spec - e.g. invalid auth details) and some network related).

@matiasAS
Copy link
Author

@MattBrittan
image

I authenticate using JWT, and I'm experiencing reconnections approximately every minute.
connection code is:

image

Regards

@MattBrittan
Copy link
Contributor

I can't see anything much of interest in the broker logs (the lack of timestamps makes it hard to get a feel for the time-frames involved). I would suggest checking the client logs as well (just in case the paho client is dropping the connection). From the look of the log you are not receiving any messages?

If both ends are just detecting loss of connection then it's a network issue (keep-alives should default to 60 seconds, so it's interesting there are none in the log). It would also be worth seeing if the connection remains up when testing with MQTTX (currently it's not clear where the problem lies).

@matiasAS
Copy link
Author

@MattBrittan
The time that the client is connected coincides with the keep alive (I tried 3600 but it still disconnected after a minute)

logs (debug) python client paho-mqtt:

image

logs broker:

image

from the websocket client in the emqx dashboard, it also disconnects, that would be a way to rule out that it is not a paho-mqtt thing

I can't connect from MQTTX

regards

@matiasAS matiasAS reopened this Jan 19, 2024
@matiasAS
Copy link
Author

sorry, I accidentally pressed close issue

@MattBrittan
Copy link
Contributor

logs (debug) python client paho-mqtt:

Nothing of real interest in these logs; it looks like the network connection is dropping (with neither the client or server initiating the disconnection).

from the websocket client in the emqx dashboard, it also disconnects,

Are you are saying that you have tested this using the websocket client in the emqx dashboard, and that fails in the same way? If so that indicates that it's not a fault with this library (given the lack of content in the EMQX log I'd guess at a network issue; perhaps try a 30s keep-alive in case something is dropping the connection after a minutes inactivity).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Available No one has claimed responsibility for resolving this issue.
Projects
None yet
Development

No branches or pull requests

2 participants