eclipse / mosquitto

Eclipse Mosquitto - An open source MQTT broker
https://mosquitto.org
Other
8.89k stars 2.36k forks source link

100% CPU Usage When Client Disconnects #2807

Open hastyeagle opened 1 year ago

hastyeagle commented 1 year ago

Hi, I'm running v2.0.15 with just one client (for now) and for some reason when that client disconnects CPU usage for the mosquitto daemon jumps to 100% and stays there. If I have the client reconnect, CPU usage immediately drops back down to virtually nothing. The second I disconnect the client again, it jumps back to 100% CPU.

Logs during the disconnect seem normal:

Client owntracks/user closed its connection.

The reconnect then seems normal as well:

New connection from 192.168.x.x:41106 on port 8883.
New client connected from 192.168.x.x:41106 as owntracks/user (p2, c0, k3600, u'user').

My conf file is:

pid_file /var/run/mosquitto.pid
user mosquitto
persistence true
persistence_location /usr/local/etc/mosquitto
persistence_file mosquitto.db
log_dest file /var/log/mosquitto.log
log_dest topic
log_type error
log_type warning
log_type notice
log_type information
connection_messages true
log_timestamp true
allow_anonymous false
password_file /usr/local/etc/mosquitto/pwfile
acl_file /usr/local/etc/mosquitto/aclfile
listener 1883 127.0.0.1
listener 8883 192.168.x.x
cafile /usr/local/etc/mosquitto/ca.crt
certfile /usr/local/etc/mosquitto/cert.crt
keyfile /usr/local/etc/mosquitto/cert.key
require_certificate true

Thanks!

hastyeagle commented 1 year ago

Just wanted to check in on this. I recently added another client (so two total). With both connected to mosquitto, if either one disconnects CPU utilization of the mosquitto daemon goes to 100%. Once I reconnect the disconnected client, CPU utilization drops back down.

Any ideas what might be causing this?

hastyeagle commented 10 months ago

Is this happening for anybody else? It's still ongoing for me. I put a cronjob in place to watch for this and restart the mosquitto server if it hits 100% CPU usage, which then forces the clients to reconnect. That works, but it'd be nice to not have to do that.

Is this a config issue, or a bug?

Thanks!

col-gh commented 9 months ago

Is this happening for anybody else?

I am experiencing very similar symptoms, but haven't yet managed to triangulate what exactly causes the looping to start. As you have reported, logs show no diagnostics and everything appears normal for a while after restarting. I am using the current version from the FreeBSD ports tree (2.0.15_1), which may not be the latest upstream.

markroos commented 1 month ago

We have the same issue. Using paho java client and 2.0.18. When client abruptly disconnects Mosquito seems to spin waiting on something from the client. If we reconnect with same mqttID the spin stops. Our code always does a disconnect and waits so we only see it on unexpected exits. Does not time out ever(days) even though socket connection is long gone. We use TCPIP noDelay FWIW.