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

killall -HUP disconnects clients #657

Closed
kartom opened this issue Dec 22, 2017 · 14 comments
Closed

killall -HUP disconnects clients #657

kartom opened this issue Dec 22, 2017 · 14 comments
Labels
Component: mosquitto-broker Status: Blocked Another issue needs to be resolved first

Comments

@kartom
Copy link

kartom commented Dec 22, 2017

The command killall -HUP which is used by i.e. the logrotate script in Ubuntu causes mosquitto to disconnect all clients, which leads to problems in some situations.

This problem seam to be realted to the reload of the configuration file and the content in the config.
I have not been able to figure out what is causing the problem but here is a mosquitto.con that makes mosquitto disconnect all clients everytime you send a killall -HUP mosquitto:

pid_file /var/run/mosquitto.pid

listener 1883

persistence true
persistence_location /var/lib/mosquitto/
persistence_file mosquitto.db

log_dest file /var/log/mosquitto/mosquitto.log
log_type all
connection_messages true
log_timestamp true

password_file /etc/mosquitto/passwd
@toast-uz
Copy link
Contributor

Could you show the version?

I reproduced this issue only on develop branch, while not on master v1.4.14. Maybe it's a bug on develop.

Result on develop branch:

$ cat test.conf 
log_type all
$ mosquitto -c test.conf &
[1] 3812
$ 1514034102: mosquitto version 1.4.90 (build date 2017-12-23 13:01:13+0000) starting
1514034102: Config loaded from test.conf.
1514034102: Opening ipv4 listen socket on port 1883.
1514034102: Opening ipv6 listen socket on port 1883.

(connected from another window)
$ 1514034117: New connection from ::1 on port 1883.
1514034117: New client connected from ::1 as mosqsub|3815-ip-172-31- (c1, k60).
1514034117: Sending CONNACK to mosqsub|3815-ip-172-31- (0, 0)
1514034117: Received SUBSCRIBE from mosqsub|3815-ip-172-31-
1514034117: 	# (QoS 0)
1514034117: mosqsub|3815-ip-172-31- 0 #
1514034117: Sending SUBACK to mosqsub|3815-ip-172-31-

$ ps -ef | grep mosquitto
centos    3812  2043  0 13:01 pts/0    00:00:00 mosquitto -c test.conf
centos    3815  2071  0 13:01 pts/1    00:00:00 mosquitto_sub -h localhost -t #
centos    3817  2043  0 13:02 pts/0    00:00:00 grep --color=auto mosquitto
$ sudo kill -s HUP 3812
$ 1514034159: Reloading config.
1514034159: Client mosqsub|3815-ip-172-31- disconnected.
1514034160: New connection from ::1 on port 1883.
1514034160: New client connected from ::1 as mosqsub|3815-ip-172-31- (c1, k60).
1514034160: Sending CONNACK to mosqsub|3815-ip-172-31- (0, 0)
1514034160: Received SUBSCRIBE from mosqsub|3815-ip-172-31-
1514034160: 	# (QoS 0)
1514034160: mosqsub|3815-ip-172-31- 0 #
1514034160: Sending SUBACK to mosqsub|3815-ip-172-31-

@toast-uz
Copy link
Contributor

Found the first bad commit by using git bisect.

4afe1a150201989681ca37abeb345fc1a074f9e5 is the first bad commit
commit 4afe1a150201989681ca37abeb345fc1a074f9e5
Author: Roger A. Light <[email protected]>
Date:   Fri Oct 2 21:44:39 2015 +0100

    Swap plugin+built in order.

:040000 040000 de5cbf93ef93db1ee9314832f4ed48f69955288a 8e20d271bf77e20488afa26438852a56d5fa10e7 M	man
:040000 040000 b7667e8a6328474f4ec72476d1ff903bcdcb57c7 330497f6892900cde64d1562c7c519f2a9a40a7c M	src

@toast-uz
Copy link
Contributor

I roughly checked the sources of the commit, but I'm not sure what is wrong. @ralight could you reconfirm it?

@kartom
Copy link
Author

kartom commented Dec 24, 2017 via email

@toast-uz
Copy link
Contributor

Thank you for the information.
Seemed a little complicated. My symptom was under only one connected client and reproduced always.

@ralight
Copy link
Contributor

ralight commented Dec 24, 2017

I've not reproduced it under 1.4.14, but have done on develop. I haven't tried the actual binary from the 1.4.14 PPA though. @kartom, if you get chance could you try a self compiled version 1.4.14? I doubt I'll be able to look any further for the next few days.

@keestux
Copy link

keestux commented Dec 31, 2017

I'm running mosquitto 1.4.14 from the PPA for Ubuntu xenial, and it shows the same behaviour. I have a sub client running all the time, and I see that it receives old retained messages when the server rotates the logs (mosquitto server gets a HUP signal).

@PierreF PierreF added Component: mosquitto-broker Status: Blocked Another issue needs to be resolved first labels Jan 5, 2018
ralight added a commit that referenced this issue Jan 10, 2018
@ralight
Copy link
Contributor

ralight commented Jan 10, 2018

I've pushed a fix for the develop branch but still haven't reproduced it on 1.4.14.

@wiebeytec
Copy link

wiebeytec commented Mar 13, 2019

I have the same issue with 1.5.3 and 1.5.5. You don't really see it with mosquitto_sub because it's quiet about its reconnects, but because I run a custom written auth plugin, I can see the messages it creates:

1552483245: Login with '[email protected]' succeeded.
1552483245: New client connected from ::1 as mosqsub|4210-duivenkrac (c1, k60, u'[email protected]').
1552483245: [Client mosqsub|4210-duivenkrac, user: [email protected]]: subscribe - '$SYS/broker': aclallow.
1552483245: mosqsub|4210-duivenkrac 0 $SYS/broker/load/messages/received/1min

1552483279: Reloading config.

1552483279: Error: An auth_opt_ option exists in the config file without an auth_plugin.
1552483279: Error found at /root/mosquitto-test-server/mosquitto-nonssl.conf:23.
1552483279: Opening MySQL.
1552483280: 33235 records refreshed from DB table 'vwUserPasswords'
1552483281: 60672 users2sites records refreshed from DB
1552483281: 31077 records refreshed from DB table 'vwSitesMqttPasswordHash'
1552483281: MySQL opened.
1552483281: Login with '[email protected]' succeeded.
1552483287: [Client mosqsub|4210-duivenkrac, user: [email protected]]: subscribe - '$SYS/broker': aclallow.

You can see the last 'login succeeded' again, and you can see the client ID is the same.

This is the mosquitto config:

pid_file /tmp/mosquitto/mosquitto.pid

persistence true
persistence_location /tmp/mosquitto/

log_dest file /tmp/mosquitto/mosquitto.log
log_type error
log_type warning
log_type notice
log_type information
log_type subscribe
log_type unsubscribe

# Otherwise it seems we're doing heaps of ACL checks for clients that don't exist anymore
persistent_client_expiration 14d

allow_anonymous false

auth_plugin /root/mosquitto-test-server/libMosquittoAuth.so.1.0.0
auth_opt_db_host 127.0.0.1
auth_opt_db_port 3306
auth_opt_db_name removed
auth_opt_db_user mqttbridge
auth_opt_db_password removed
auth_opt_log_acl_checks true

listener 11883

Started with /opt/mosquitto-1.5.3/src/mosquitto -c /root/mosquitto-test-server/mosquitto-nonssl.conf.

This is a self-compiled binary.

(I don't know why it's saying I don't have auth_plugin, because I do, and it works).

@ralight
Copy link
Contributor

ralight commented Sep 17, 2019

For some people this could be due to the logrotate script on Debian incorrectly calling "killall mosquitto", which would kill any tasks with mosquitto in the name, not just the mosquitto broker. This is being fixed now.

For completely self compiled and installed binaries that won't be the cause.

@wiebeytec
Copy link

I'm confused. Why would this be the cause? I only have Mosquitto running as broker on the server, nothing else by that name.

@ralight
Copy link
Contributor

ralight commented Sep 18, 2019

That's why I said "for some people". If you had clients running on the same machine as the broker, with "mosquitto" in their name, then they would be unexpectedly sent a HUP.

@daenney
Copy link

daenney commented Jan 18, 2020

I'm getting this too. I just upgraded to 1.6.8 b/c of #1459 and though the error related to that one is gone, a HUP still kills all client connections.

I run from the Docker container, as a systemd service:

[Unit]
Description=Mosquitto
After=docker.service
Requires=docker.service

[Service]
ExecStartPre=-/usr/bin/docker rm mosquitto
ExecStart=-/usr/bin/docker run \
                           --name mosquitto \
                           --read-only \
                           -p 127.0.0.1:1883:1883 \
                           -p 127.0.0.1:9001:9001 \
                           --expose 1883 \
                           --expose 9001 \
                           -v mosquitto_data:/mosquitto/data:rw \
                           -v /etc/docker/config/mosquitto:/mosquitto/config:ro \
                           eclipse-mosquitto:1.6.8
ExecReload=/usr/bin/docker kill -s HUP mosquitto
ExecStop=-/usr/bin/docker stop mosquitto

[Install]
WantedBy=multi-user.target
$ systemctl reload mosquitto
$ journalctl -u mosquitto
[..]
Jan 18 16:12:07 endor systemd[1]: Reloading Mosquitto.
Jan 18 16:12:08 endor docker[17116]: mosquitto
Jan 18 16:12:08 endor systemd[1]: Reloaded Mosquitto.
Jan 18 16:12:08 endor docker[16612]: Reloading config.
Jan 18 16:12:08 endor docker[16612]: Loading config file /mosquitto/config/conf.d/plain.conf
Jan 18 16:12:08 endor docker[16612]: Loading config file /mosquitto/config/conf.d/websockets.conf
Jan 18 16:12:08 endor docker[16612]: Client fargton-53511d5f-212a-408a-babb-2cc418264223 disconnected.
Jan 18 16:12:08 endor docker[16612]: Client fargton-209725c9-28be-439a-8c72-b6cf84c15885 disconnected.
Jan 18 16:12:08 endor docker[16612]: Client dammsugare-829468be-e469-485a-bd35-00c6ebc2fbfa disconnected.
Jan 18 16:12:08 endor docker[16612]: Client rodljus-3891e934-fff8-4ce6-925a-531425dbf10e disconnected.
[..]

@ralight
Copy link
Contributor

ralight commented Dec 22, 2020

I think this has been fixed. The issue is around files not being accessible after root privileges have been dropped.

@ralight ralight closed this as completed Dec 23, 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
Component: mosquitto-broker Status: Blocked Another issue needs to be resolved first
Projects
None yet
Development

No branches or pull requests

7 participants