Mosquitto crashing repeatedly with potential memory leak?

I’m running the ‘standard’ HA build (core 2025.12.3 OS 16.3) on a Raspberry Pi with Mosquitto add-on 6.5.2 (core is 2.0.22). At intervals, Mosquitto is quitting and restarting…

[05:52:22] INFO: Service restart after closing
[05:52:25] INFO: Starting mosquitto MQTT broker...
2026-01-06 05:52:25: mosquitto version 2.0.22 starting
2026-01-06 05:52:25: Config loaded from /etc/mosquitto/mosquitto.conf.
2026-01-06 05:52:25: Loading plugin: /usr/share/mosquitto/go-auth.so
[05:52:25] INFO: Successfully send service information to the Supervisor.
2026-01-06 05:52:25: Warning: Mosquitto should not be run as root/administrator.
[05:52:26] INFO: Successfully send discovery information to Home Assistant.
2026-01-06 05:52:25: ├── Username/password checking enabled.
2026-01-06 05:52:25: ├── TLS-PSK checking enabled.
2026-01-06 05:52:25: └── Extended authentication not enabled.
2026-01-06 05:52:25: Opening ipv4 listen socket on port 1883.
2026-01-06 05:52:25: Opening ipv6 listen socket on port 1883.
2026-01-06 05:52:25: Opening websockets listen socket on port 1884.
2026-01-06 05:52:25: Opening ipv4 listen socket on port 8883.
2026-01-06 05:52:25: Opening ipv6 listen socket on port 8883.
2026-01-06 05:52:25: Opening websockets listen socket on port 8884.
2026-01-06 05:52:25: mosquitto version 2.0.22 running
2026-01-06 05:52:29: New connection from 192.168.1.6:59482 on port 1883.
2026-01-06 05:52:29: New connection from ::1:44682 on port 1883.
2026-01-06 05:52:29: New client connected from 192.168.1.6:59482 as ems-esp (p2, c1, k60, u'mqttems').
2026-01-06 05:52:29: Client <unknown> disconnected due to protocol error.
2026-01-06 05:52:33: New connection from 172.30.32.1:41361 on port 1883.
[05:52:35] INFO: Successfully send service information to the Supervisor.
[05:52:40] INFO: Successfully send discovery information to Home Assistant.
2026-01-06 05:52:33: New client connected from 172.30.32.1:41361 as 7e3rsUYvmI39dabKV7ShII (p2, c1, k60, u'homeassistant').
2026-01-06 05:52:40: New connection from 192.168.1.237:56263 on port 1883.
2026-01-06 05:52:40: New client connected from 192.168.1.237:56263 as ESP32_545178 (p2, c1, k120, u'mqttihd').
[05:52:50] INFO: Successfully send service information to the Supervisor.
2026-01-06 05:53:03: New connection from 172.30.32.2:55822 on port 1883.
2026-01-06 05:53:03: Client <unknown> closed its connection.
[05:53:10] INFO: Service restart after closing
[05:53:12] INFO: Starting mosquitto MQTT broker...
2026-01-06 05:53:12: Warning: Mosquitto should not be run as root/administrator.
2026-01-06 05:53:12: mosquitto version 2.0.22 starting
2026-01-06 05:53:12: Config loaded from /etc/mosquitto/mosquitto.conf.
2026-01-06 05:53:12: Loading plugin: /usr/share/mosquitto/go-auth.so
2026-01-06 05:53:12: ├── Username/password checking enabled.
2026-01-06 05:53:12: ├── TLS-PSK checking enabled.
2026-01-06 05:53:12: └── Extended authentication not enabled.
2026-01-06 05:53:12: Opening ipv4 listen socket on port 1883.
2026-01-06 05:53:12: Opening ipv6 listen socket on port 1883.
2026-01-06 05:53:12: Opening websockets listen socket on port 1884.
2026-01-06 05:53:12: Opening ipv4 listen socket on port 8883.
2026-01-06 05:53:12: Opening ipv6 listen socket on port 8883.
2026-01-06 05:53:12: Opening websockets listen socket on port 8884.
2026-01-06 05:53:12: mosquitto version 2.0.22 running
2026-01-06 05:53:17: New connection from ::1:37200 on port 1883.
2026-01-06 05:53:17: Client <unknown> disconnected due to protocol error.
2026-01-06 05:53:17: New connection from 192.168.1.6:59485 on port 1883.
2026-01-06 05:53:17: New client connected from 192.168.1.6:59485 as ems-esp (p2, c1, k60, u'mqttems').
2026-01-06 05:53:20: New connection from 172.30.32.1:53927 on port 1883.
2026-01-06 05:53:20: New client connected from 172.30.32.1:53927 as 7e3rsUYvmI39dabKV7ShII (p2, c1, k60, u'homeassistant').
2026-01-06 05:53:25: New connection from 192.168.1.237:56268 on port 1883.
2026-01-06 05:53:25: New client connected from 192.168.1.237:56268 as ESP32_545178 (p2, c1, k120, u'mqttihd').
[05:53:30] INFO: Successfully send discovery information to Home Assistant.
[05:53:37] INFO: Successfully send service information to the Supervisor.
[05:53:51] INFO: Service restart after closing
[05:53:53] INFO: Starting mosquitto MQTT broker...
2026-01-06 05:53:54: mosquitto version 2.0.22 starting
2026-01-06 05:53:54: Config loaded from /etc/mosquitto/mosquitto.conf.
2026-01-06 05:53:54: Loading plugin: /usr/share/mosquitto/go-auth.so
2026-01-06 05:53:54: ├── Username/password checking enabled.
2026-01-06 05:53:54: ├── TLS-PSK checking enabled.
2026-01-06 05:53:54: └── Extended authentication not enabled.
2026-01-06 05:53:54: Warning: Mosquitto should not be run as root/administrator.
2026-01-06 05:53:54: Opening ipv4 listen socket on port 1883.
2026-01-06 05:53:54: Opening ipv6 listen socket on port 1883.
2026-01-06 05:53:54: Opening websockets listen socket on port 1884.
2026-01-06 05:53:54: Opening ipv4 listen socket on port 8883.
2026-01-06 05:53:54: Opening ipv6 listen socket on port 8883.
2026-01-06 05:53:54: Opening websockets listen socket on port 8884.
2026-01-06 05:53:54: mosquitto version 2.0.22 running
2026-01-06 05:54:00: New connection from ::1:50724 on port 1883.
2026-01-06 05:54:00: Client <unknown> disconnected due to protocol error.
2026-01-06 05:54:00: New connection from 192.168.1.6:59489 on port 1883.
2026-01-06 05:54:00: New client connected from 192.168.1.6:59489 as ems-esp (p2, c1, k60, u'mqttems').
2026-01-06 05:54:04: New connection from 172.30.32.1:55295 on port 1883.
2026-01-06 05:54:04: New client connected from 172.30.32.1:55295 as 7e3rsUYvmI39dabKV7ShII (p2, c1, k60, u'homeassistant').
2026-01-06 05:54:08: New connection from 192.168.1.237:56272 on port 1883.
2026-01-06 05:54:08: New client connected from 192.168.1.237:56272 as ESP32_545178 (p2, c1, k120, u'mqttihd').
[05:54:14] INFO: Successfully send discovery information to Home Assistant.
[05:54:24] INFO: Successfully send service information to the Supervisor.

Concurrent with these Mosquitto logs, the host log appears to be flagging an OOM (out of memory?) event…

2026-01-06 05:53:10.388 homeassistant kernel: oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0,global_oom,task_memcg=/system.slice/docker-eb8afa7a3a23384c6023dbdea7378c2e227a53f049cfe5afc9f5610b7b326900.scope,task=mosquitto,pid=347656,uid=0

2026-01-06 05:53:10.389 homeassistant kernel: Out of memory: Killed process 347656 (mosquitto) total-vm:1433652kB, anon-rss:27008kB, file-rss:672kB, shmem-rss:0kB, UID:0 pgtables:268kB oom_score_adj:200

2026-01-06 05:53:10.389 homeassistant systemd[1]: docker-eb8afa7a3a23384c6023dbdea7378c2e227a53f049cfe5afc9f5610b7b326900.scope: A process of this unit has been killed by the OOM killer.

In parallel, I’m seeing creeping increasing RAM usage with a drop back after each Mosquitto crash:

So… does my Mosquitto instance have a memory leak which is causing the crashes? How do I go about troubleshooting that?

Maybe, maybe not. It could be something else leaking causing Mosquitto to crash.

Turn off the broker add-on and see if the leak continues to occur. Yes = not the add-on.

Restart in safe mode and see if the leek continues to occur. No = third party integration.

How much RAM does your pi have?

Do you run the VSCode add-on?

That is a memory hog. So is the Firefox add-on.

For what it is worth I also run the Mosquitto add-on and am not seeing a memory leak.

Though this person is suffering the same issue: Mosquitto broker restarts every few minutes

1 Like

Don’t run either Firefox or VSCode add-ons. Just using Mosquitto, File Editor, Samba, SSH & Terminal.

I don’t know if the crashing is reliable enough to check it with Mosquitto enabled or Safe Mode, but I’ll see what I can find.

My RPi3 has 1GB RAM. Total usage peaks at around 85% and Mosquitto claims to be using around 3%.

Very similar to Mosquitto broker restarts every few minutes

As you said, it is very similar. I would say the same. You did not read the thread then? The answer is there:

It says in HA docs:

TOOLS REQUIRED: Raspberry Pi 4 or 5 with power supply (minimum 2 GB RAM)

Indeed. But all the time it was running happily on a RPi3 with 1GB RAM, I (and many other users) weren’t going to be checking the advancing hardware requirements!

So… time to go shopping. I run a separate data partition on an external 120GB SSD, so I’ll have to read up on how to migrate to new hardware and restore from backup.

My advice, skip on RPI5 and buy a NUC. Same price point (when SSD, case, adapter taken into account). lot faster, more memory. Be fast though, memory prices are souring. So if you buy a pre built when memory prices were normal then you’re fine. If they need to buy new memory for it, expect total price to double.

3 Likes

Interesting watching if you are in the market for new hardware: https://youtu.be/YDM4lewqz9U?si=aQuGgVeFSUV1ypU3

Thanks - interesting. Yes…

Just checked. I bought my RPi3, case and PSU in Jan 2017 for 57 GBP. I added a 120GB external SSD and enclosure for 23 GBP in Sept 2020 and I’ll migrate that data drive to the new build. So 80 GBP all in for 8 years service :grin:

I only need the hardware to run HA - it’s installed next to my boiler, boiler interface, smart meter kit etc - so it only has one job to do, as simply and straightforwardly as possible. A NUC would be an intergalactic sledgehammer to crack a tiny nut and I’ve only used 13% of the data disk.

So… I’ve ordered a 4GB RPi5, diecast aluminium case for passive cooling (don’t want a fan, this thing is on 24/7/365 - simplicity, reliability, low energy) and PSU for 90 GBP. If I get another 8 years out of it like the RPi3, that won’t be too shabby…

(And my son and I have been thinking about Pi-hole, so the RPi3 won’t go to waste either)

I get the idea of something like a NUC to host multiple embedded services but I’m not there yet.

As a stop-gap til the new toys arrive, I’ve just added 2G of swap. Not a perfect or long-term fix but early signs are that RAM usage is down from over 80% to under 60% with no dramatic performance hit, so I’ll take that for now…

I used

image