mosquitto Error: Address already in use Topic is solved

Having issues with your DietPi installation or found a bug? Post it here.
User avatar
MichaIng
Site Admin
Posts: 3097
Joined: Sat Nov 18, 2017 6:21 pm

Re: mosquitto Error: Address already in use

Post by MichaIng »

Yes, I'm just wondering what starts it. I cannot see a second service at least. Or some internal issue makes it spawn multiple instances?

Currently difficult to have a closer look here, as my phone cannot open .deb files.

If you stop the service, is there still a Mosquitto instance running? systemctl stop mosquitto
In case you could mask it: systemctl mask mosquitto
If no other instance is up then, we know that it internally somehow spawns multiple instances.
User avatar
Joulinar
Posts: 5115
Joined: Sat Nov 16, 2019 12:49 am

Re: mosquitto Error: Address already in use

Post by Joulinar »

we can try as well an older version of mosquitto. It's not that difficult to remove 2.0.9 and install 2.0.8 or 2.0.7

Do you know the version used before?

I did a test installation on RPi 32bit as well as 64bit. Both are working fine. Strange. Could it be some config files invoke which will create a 2nd instance?

32bit

Code: Select all

root@DietPi3:~# journalctl -u mosquitto
-- Logs begin at Sat 2021-03-20 22:41:40 CET, end at Sat 2021-03-20 22:42:45 CET. --
Mar 20 22:41:58 DietPi3 systemd[1]: Starting Mosquitto MQTT Broker...
Mar 20 22:41:58 DietPi3 systemd[1]: Started Mosquitto MQTT Broker.
root@DietPi3:~# cat /var/log/mosquitto/mosquitto.log
1616276518: mosquitto version 2.0.9 starting
1616276518: Config loaded from /etc/mosquitto/mosquitto.conf.
1616276518: Starting in local only mode. Connections will only be possible from clients running on this machine.
1616276518: Create a configuration file which defines a listener to allow remote access.
1616276518: Opening ipv4 listen socket on port 1883.
1616276518: Opening ipv6 listen socket on port 1883.
1616276518: Error: Cannot assign requested address
1616276518: mosquitto version 2.0.9 running
root@DietPi3:~#
64bit

Code: Select all

root@DietPi4:~# journalctl -u mosquitto
-- Logs begin at Thu 2019-02-14 11:11:58 CET, end at Sat 2021-03-20 22:36:27 CET. --
Mar 20 22:35:40 DietPi4 systemd[1]: Starting Mosquitto MQTT v3.1/v3.1.1 Broker...
Mar 20 22:35:40 DietPi4 systemd[1]: Started Mosquitto MQTT v3.1/v3.1.1 Broker.
root@DietPi4:~# cat /var/log/mosquitto/mosquitto.log
1616276140: mosquitto version 1.5.7 starting
root@DietPi4:~#
Fun fact, 32bit will install 2.0.9 while 64bit is still 1.5.7 :)
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
Ian
Posts: 29
Joined: Thu Feb 28, 2019 12:45 pm

Re: mosquitto Error: Address already in use

Post by Ian »

After systemctl stop mosquitto and checking mosquitto

I'm now not getting an error but still only in local mode.

Code: Select all

root@DietPi:~# mosquitto
1616324408: mosquitto version 2.0.9 starting
1616324408: Using default config.
1616324408: Starting in local only mode. Connections will only be possible from clients running on this machine.
1616324408: Create a configuration file which defines a listener to allow remote access.
1616324408: Opening ipv4 listen socket on port 1883.
1616324408: Opening ipv6 listen socket on port 1883.
1616324408: mosquitto version 2.0.9 running
1616324409: New connection from 127.0.0.1:53278 on port 1883.
1616324409: New client connected from 127.0.0.1:53278 as mqtt_154a2846.3b1378 (p1, c1, k60).
1616324415: New connection from 127.0.0.1:53280 on port 1883.
1616324415: New client connected from 127.0.0.1:53280 as mqtt_7623cef0.cf7 (p1, c1, k60).
User avatar
Joulinar
Posts: 5115
Joined: Sat Nov 16, 2019 12:49 am

Re: mosquitto Error: Address already in use

Post by Joulinar »

The local connection seems to be a security feature since version 2. You would need to configure authentication on your Mosquitto instance

https://mosquitto.org/documentation/aut ... n-methods/
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
Ian
Posts: 29
Joined: Thu Feb 28, 2019 12:45 pm

Re: mosquitto Error: Address already in use

Post by Ian »

Yes I saw that, but for now it does seem to be another instance running somewhere as I did a reboot checked mosquitto and I'm back to square one with the error.

Again systemctl stop mosquitto and there's no error.

Would like to get to the bottom of this.
User avatar
Joulinar
Posts: 5115
Joined: Sat Nov 16, 2019 12:49 am

Re: mosquitto Error: Address already in use

Post by Joulinar »

question. How do you check mosquitto. do you simply type the command into the console? Because this will not check mosquitto. This command will start a 2nd instance of mosquitto, which of course is conflicting with the systemd service

Better to check mosquitto as follow after system was rebooted.

Code: Select all

systemctl status mosquitto.service
cat /var/log/mosquitto/mosquitto.log
ss -tulpn | grep mosquitto
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
Ian
Posts: 29
Joined: Thu Feb 28, 2019 12:45 pm

Re: mosquitto Error: Address already in use

Post by Ian »

Oops yes I was, that was unknown to me sorry. I've been chasing my tail :roll:

So it was just the update to vers. 2.0.9 local only thing blocking incoming messages, how embarrassing :roll:

Thanks for your help, time and patience.

I'll edited the config file later and let you know.

Regards
Ian

Code: Select all

root@DietPi:~# systemctl status mosquitto.service
● mosquitto.service - Mosquitto MQTT Broker
   Loaded: loaded (/lib/systemd/system/mosquitto.service; disabled; vendor preset: enabled)
   Active: active (running) since Sun 2021-03-21 12:54:04 CET; 17s ago
     Docs: man:mosquitto.conf(5)
           man:mosquitto(8)
  Process: 813 ExecStartPre=/bin/chown mosquitto: /var/run/mosquitto (code=exited, status=0/SUCCES
S)
  Process: 811 ExecStartPre=/bin/mkdir -m 740 -p /var/run/mosquitto (code=exited, status=0/SUCCESS
)
  Process: 808 ExecStartPre=/bin/chown mosquitto: /var/log/mosquitto (code=exited, status=0/SUCCES
S)
  Process: 805 ExecStartPre=/bin/mkdir -m 740 -p /var/log/mosquitto (code=exited, status=0/SUCCESS
)
 Main PID: 818 (mosquitto)
    Tasks: 1 (limit: 4915)
   CGroup: /system.slice/mosquitto.service
           └─818 /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf

Mar 21 12:54:03 DietPi systemd[1]: Starting Mosquitto MQTT Broker...
Mar 21 12:54:04 DietPi systemd[1]: Started Mosquitto MQTT Broker.
root@DietPi:~# cat /var/log/mosquitto/mosquitto.log
1616327644: mosquitto version 2.0.9 starting
1616327644: Config loaded from /etc/mosquitto/mosquitto.conf.
1616327644: Starting in local only mode. Connections will only be possible from clients running on this machine.
1616327644: Create a configuration file which defines a listener to allow remote access.
1616327644: Opening ipv4 listen socket on port 1883.
1616327644: Opening ipv6 listen socket on port 1883.
1616327644: mosquitto version 2.0.9 running
root@DietPi:~# ss -tulpn | grep mosquitto
tcp    LISTEN     0      100    127.0.0.1:1883                  *:*                   users:(("mosquitto",pid=818,fd=5))
tcp    LISTEN     0      100     ::1:1883                 :::*                   users:(("mosquitto",pid=818,fd=6))
Ian
Posts: 29
Joined: Thu Feb 28, 2019 12:45 pm

Re: mosquitto Error: Address already in use

Post by Ian »

I have it running again with the code below added to the mosquitto.conf file.

Sorry again for wasting your time, I'm still learning by doing.

Code: Select all

listener 1883
allow_anonymous true
User avatar
Joulinar
Posts: 5115
Joined: Sat Nov 16, 2019 12:49 am

Re: mosquitto Error: Address already in use

Post by Joulinar »

at least we found it ;)
Pls let us know if a solution is working. This could help others if they hit by similar situation. Your DietPi Team
User avatar
novitibo
Posts: 120
Joined: Mon Feb 29, 2016 5:11 pm

Re: mosquitto Error: Address already in use

Post by novitibo »

Post Reply