Openhab crashes with out of memory

Today my openhab went out of memory.
Version 4.1.3
HW: RPI running bullseye

2024-07-02 01:26:16.027 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.io.monitor.internal.EventLogger@105d6b3' takes more than 5000ms.
2024-07-02 01:26:17.564 [WARN ] [io.openhabcloud.internal.CloudClient] - Socket.IO disconnected: ping timeout
2024-07-02 01:26:19.176 [INFO ] [io.openhabcloud.internal.CloudClient] - Disconnected from the openHAB Cloud service (UUID = d7...0f, base URL = http://localhost:8080)
2024-07-02 01:26:31.934 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.io.monitor.internal.EventLogger@105d6b3' takes more than 5000ms.
2024-07-02 01:26:43.088 [INFO ] [io.openhabcloud.internal.CloudClient] - Connected to the openHAB Cloud service (UUID = d7...0f, base URL = http://localhost:8080)
2024-07-02 01:26:57.438 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.thing.internal.CommunicationManager@1244023' takes more than 5000ms.
2024-07-02 01:27:19.121 [WARN ] [io.openhabcloud.internal.CloudClient] - Socket.IO disconnected: ping timeout
2024-07-02 01:27:22.151 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.thing.internal.CommunicationManager@1244023' takes more than 5000ms.
2024-07-02 01:27:26.907 [INFO ] [io.openhabcloud.internal.CloudClient] - Disconnected from the openHAB Cloud service (UUID = d7...0f, base URL = http://localhost:8080)
2024-07-02 01:27:33.233 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.thing.internal.CommunicationManager@1244023' takes more than 5000ms.
2024-07-02 01:27:48.782 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.thing.internal.CommunicationManager@1244023' takes more than 5000ms.
2024-07-02 01:28:00.112 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.thing.internal.CommunicationManager@1244023' takes more than 5000ms.
2024-07-02 01:28:03.190 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.internal.items.ItemUpdater@1074a4b' takes more than 5000ms.
2024-07-02 01:28:09.574 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.thing.internal.CommunicationManager@1244023' takes more than 5000ms.
2024-07-02 01:28:15.874 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.io.monitor.internal.EventLogger@105d6b3' takes more than 5000ms.
2024-07-02 01:28:17.423 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.thing.internal.CommunicationManager@1244023' takes more than 5000ms.
2024-07-02 01:28:26.864 [INFO ] [io.openhabcloud.internal.CloudClient] - Connected to the openHAB Cloud service (UUID = d7...0f, base URL = http://localhost:8080)
2024-07-02 01:28:28.487 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.thing.internal.CommunicationManager@1244023' takes more than 5000ms.
2024-07-02 01:28:43.944 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.thing.internal.CommunicationManager@1244023' takes more than 5000ms.
2024-07-02 01:28:57.724 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.thing.internal.CommunicationManager@1244023' takes more than 5000ms.
2024-07-02 01:29:05.517 [WARN ] [io.openhabcloud.internal.CloudClient] - Socket.IO disconnected: ping timeout
2024-07-02 01:29:05.527 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.thing.internal.CommunicationManager@1244023' takes more than 5000ms.
2024-07-02 01:29:07.041 [INFO ] [io.openhabcloud.internal.CloudClient] - Disconnected from the openHAB Cloud service (UUID = d7...0f, base URL = http://localhost:8080)
2024-07-02 01:29:26.920 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.internal.items.ItemUpdater@1074a4b' takes more than 5000ms.
2024-07-02 01:29:56.184 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.thing.internal.CommunicationManager@1244023' takes more than 5000ms.
2024-07-02 01:30:09.823 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.thing.internal.CommunicationManager@1244023' takes more than 5000ms.
2024-07-02 01:30:23.574 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.io.monitor.internal.EventLogger@105d6b3' takes more than 5000ms.
2024-07-02 01:30:25.323 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.thing.internal.CommunicationManager@1244023' takes more than 5000ms.
2024-07-02 01:30:28.288 [INFO ] [io.openhabcloud.internal.CloudClient] - Connected to the openHAB Cloud service (UUID = d7...0f, base URL = http://localhost:8080)
2024-07-02 01:30:38.844 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.io.monitor.internal.EventLogger@105d6b3' takes more than 5000ms.
2024-07-02 01:30:43.436 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.internal.items.ItemUpdater@1074a4b' takes more than 5000ms.
2024-07-02 01:30:51.096 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.internal.items.ItemUpdater@1074a4b' takes more than 5000ms.
2024-07-02 01:31:01.931 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.thing.internal.CommunicationManager@1244023' takes more than 5000ms.
2024-07-02 01:31:06.458 [WARN ] [io.openhabcloud.internal.CloudClient] - Socket.IO disconnected: ping timeout
2024-07-02 01:31:08.037 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.thing.internal.CommunicationManager@1244023' takes more than 5000ms.
2024-07-02 01:31:15.564 [INFO ] [io.openhabcloud.internal.CloudClient] - Disconnected from the openHAB Cloud service (UUID = d7...0f, base URL = http://localhost:8080)
2024-07-02 01:31:26.348 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.thing.internal.CommunicationManager@1244023' takes more than 5000ms.
2024-07-02 01:31:43.071 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.thing.internal.CommunicationManager@1244023' takes more than 5000ms.
2024-07-02 01:31:56.814 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.thing.internal.CommunicationManager@1244023' takes more than 5000ms.
2024-07-02 01:32:07.241 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.internal.items.ItemUpdater@1074a4b' takes more than 5000ms.
2024-07-02 01:32:19.065 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.thing.internal.CommunicationManager@1244023' takes more than 5000ms.
2024-07-02 01:32:28.128 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.internal.items.ItemUpdater@1074a4b' takes more than 5000ms.
2024-07-02 01:32:54.774 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.thing.internal.CommunicationManager@1244023' takes more than 5000ms.
2024-07-02 01:33:11.510 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.thing.internal.CommunicationManager@1244023' takes more than 5000ms.
2024-07-02 01:33:29.510 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.thing.internal.CommunicationManager@1244023' takes more than 5000ms.
2024-07-02 01:34:22.800 [WARN ] [com.zaxxer.hikari.pool.HikariPool   ] - 45s864ms319μs94ns - Thread starvation or clock leap detected (housekeeper delta=yank-default).
2024-07-02 01:34:45.272 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.thing.internal.CommunicationManager@1244023' takes more than 5000ms.
2024-07-02 01:34:48.213 [INFO ] [io.openhabcloud.internal.CloudClient] - Connected to the openHAB Cloud service (UUID = d7...0f, base URL = http://localhost:8080)
2024-07-02 01:35:12.144 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.io.monitor.internal.EventLogger@105d6b3' takes more than 5000ms.
2024-07-02 01:35:21.191 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.io.monitor.internal.metrics.ThingStateMetric@7c2914' takes more than 5000ms.
2024-07-02 01:35:25.579 [WARN ] [io.openhabcloud.internal.CloudClient] - Socket.IO disconnected: ping timeout
2024-07-02 01:35:41.884 [INFO ] [io.openhabcloud.internal.CloudClient] - Disconnected from the openHAB Cloud service (UUID = d7...0f, base URL = http://localhost:8080)
2024-07-02 01:36:14.999 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.internal.items.ItemUpdater@1074a4b' takes more than 5000ms.
2024-07-02 01:36:59.279 [WARN ] [com.zaxxer.hikari.pool.HikariPool   ] - 47s292ms659μs479ns - Thread starvation or clock leap detected (housekeeper delta=yank-default).
2024-07-02 01:37:06.995 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.thing.internal.CommunicationManager@1244023' takes more than 5000ms.
2024-07-02 01:37:27.816 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.internal.items.ItemUpdater@1074a4b' takes more than 5000ms.
2024-07-02 01:37:51.686 [WARN ] [com.zaxxer.hikari.pool.HikariPool   ] - 52s399ms448μs650ns - Thread starvation or clock leap detected (housekeeper delta=yank-default).
2024-07-02 01:37:59.384 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.internal.items.ItemUpdater@1074a4b' takes more than 5000ms.
2024-07-02 01:39:09.481 [WARN ] [com.zaxxer.hikari.pool.HikariPool   ] - 54s873ms900μs845ns - Thread starvation or clock leap detected (housekeeper delta=yank-default).
2024-07-02 01:40:44.761 [WARN ] [com.zaxxer.hikari.pool.HikariPool   ] - 1m33s127ms544μs550ns - Thread starvation or clock leap detected (housekeeper delta=yank-default).
2024-07-02 01:45:08.209 [WARN ] [ab.core.internal.events.EventHandler] - Dispatching event to subscriber 'org.openhab.core.thing.internal.CommunicationManager@1244023' takes more than 5000ms.
2024-07-02 01:45:08.209 [WARN ] [mmon.WrappedScheduledExecutorService] - Scheduled runnable ended with an exception:
java.lang.OutOfMemoryError: Java heap space
● openhab.service - openHAB - empowering the smart home
     Loaded: loaded (/lib/systemd/system/openhab.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2024-06-25 01:01:18 BST; 1 weeks 0 days ago
       Docs: https://www.openhab.org/docs/
             https://community.openhab.org
   Main PID: 32564 (java)
      Tasks: 286 (limit: 4915)
        CPU: 4d 12h 32min 54.609s
     CGroup: /system.slice/openhab.service
             └─32564 /usr/bin/java -XX:-UsePerfData -Dopenhab.home=/usr/share/openhab -Dopenhab.conf=/etc/openhab -Dopenhab.runtime=/usr/share/openhab/runtime -Dopenhab.userdata=/var/lib/openhab -Dopenhab.logdir=/var/log/openhab -Dfelix.cm.dir=/v>

Jul 02 01:37:36 openhab karaf[32564]:         at org.openhab.binding.network.internal.PresenceDetection.performSystemPing(PresenceDetection.java:551)
Jul 02 01:37:39 openhab karaf[32564]:         at org.openhab.binding.network.internal.PresenceDetection.lambda$5(PresenceDetection.java:350)
Jul 02 01:37:41 openhab karaf[32564]:         at org.openhab.binding.network.internal.PresenceDetection$$Lambda$1541/0x9aa27320.run(Unknown Source)
Jul 02 01:37:42 openhab karaf[32564]:         at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
Jul 02 01:37:50 openhab karaf[32564]:         at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
Jul 02 01:37:50 openhab karaf[32564]:         at java.base/java.lang.Thread.run(Thread.java:840)
Jul 02 01:38:08 openhab karaf[32564]: Exception in thread "presenceDetectionICMP_pclab" java.lang.OutOfMemoryError: Java heap space
Jul 02 01:40:47 openhab karaf[32564]: Exception in thread "presenceDetectionICMP_pcandre" Exception in thread "presenceDetectionICMP_mcserver"         at java.base/java.io.BufferedInputStream.<init>(BufferedInputStream.java:201)
Jul 02 01:40:49 openhab karaf[32564]:         at java.base/java.io.BufferedInputStream.<init>(BufferedInputStream.java:181)
Jul 02 01:41:19 openhab karaf[32564]:         at java.base/java.lang.ProcessImpl$ProcessPipeInputStream.<init>(ProcessImpl.java:578)
~

After a service restart, it became normal again. From the logs is there anything I can look for?

Thanks.

I had the same and I increased the size of stack and heap in /etc/default/openhab

EXTRA_JAVA_OPTS="-Xms1024m -Xmx2048m"
.
The problem did not occur again so at least in my case it was not a memory leak (I’m on 4.2M3).
So you may want to give that a try. Depending on available memory on your machine and current settings you may need to use different values. Default is 512/1024 if I remember correctly.

Move to openHABian. It takes care of memory related and many other settings.
Just export your config and install a fresh SD with latest openHABian then import your old config.