Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
134 views
in Technique[技术] by (71.8m points)

Mosquitto over mqtt takes a long time when websockets active 2.0.5

I recently updated my Mosquitto broker from 1.6.12 up to the latest 2.0.5. I have both a standard mqtt port and a websocket port set up. Since upgrading I have noticed strange behaviour where messages (including connecting, subscribing) sent from clients connecting over the 'standard' port would take very long (sometimes up to a couple minutes), while the clients using websockets would connect almost instantly. To make things weirder, if I sent a message from a websocket client while a 'standard' client was still waiting, the websocket message seems to 'push through' and all other messages are also immediately resolved.

To make that last point clearer, two examples:

Client A (using standard port) tries to connect. Nothing else happens. Perhaps 40-80 seconds later, finally connects.

Client A (using standard port) tries to connect. 2 seconds later, Client B (using websockets) tries to connect. Immediately, both Client A and Client B (in that order) successfully connect.

My .conf file:

pid_file /var/run/mosquitto/mosquitto.pid

persistence true
persistence_location /var/lib/mosquitto/

log_dest file /var/log/mosquitto/mosquitto.log

# mqtt
listener 1883
protocol mqtt

# websockets
listener 9001
protocol websockets

allow_zero_length_clientid true
allow_anonymous false

# Auth plugin
auth_plugin /usr/lib/mosquitto/auth_plugin_pyauth.so
auth_opt_pyauth_module openid_mosquitto_auth

NOTE I did already test if it was a problem with the auth plugin, but it is not. Even with a dummy plugin that immediately returns success for all functions, the problem persists.

So, my question: Is this a problem with my conf file? Is it a bug in Mosquitto? Could it be a problem in my system? Any ideas would be appreciated.

Further tests

  • Tried with log_type all but nothing unexpected came up.
  • Tried allow_anonymous true and removing the auth plugin, but problem persists.
  • Tried removing the websocket port completely, and it fixed the problem for the standard port (!!) So I guess my issue lies somewhere in how websockets was build?? It's still confusing to me how the websockets port could be causing problems for clients using the standard port, but I'll dig into it a bit more.

Solution

as @ralight suggested, I tried using libwebsockets 2.4.2 instead of the latest 4.1.6, and that seems to have solved it. Not sure why the new version causes this. Should I be reporting this to Mosquitto and/or libwebsockets?

Anyway, I'm happy its working so thanks again.

question from:https://stackoverflow.com/questions/65887871/mosquitto-over-mqtt-takes-a-long-time-when-websockets-active-2-0-5

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...