Memory leak in Roon Bridge RAAT server causing performance issues (ref#TE8Y8F)[Ticket in]

Hi! What’s not quite right with Roon?

· None of the above quite fits

None of the above quite fits

· None of these quite match

Tell us what's going on

· Memory leak in Roon Bridge RAAT server

Tell us about your home network

· Ethernet all 1GB no WiFi

I uploaded a PDF with the in detail analysis. But can’t see it above.

I’ll post all here again :frowning:

Memory leak in Roon Bridge RAAT server

Situation

Since the latest update of Roon Bridge I first encountered some severe dropouts during playback and right after that playback stopped completely.

As Roon Bridge runs on a Raspberry Pi4 I tried to log in and look what happened. But I gut no more login prompt. The Pi4 could be pinged but disappeared in Roon Playback devices.

Had to reboot the Pi to bring Roon Bridge back to life.

Setup

  • Roon Server on Windows11

  • Roon Server 2.73 Build 1700

  • Roon Bridge on Pi4 with Dietpi

uname -a
Linux DEVELOP 5.15.61-v8+ #1579 SMP PREEMPT Fri Aug 26 11:16:44 BST 2022 aarch64 GNU/Linux

cat /opt/RoonBridge/Bridge/VERSION
207101683
2.71 (build 1683) production

  • Connected to RME ADI-2/4 Pro SE via USB in Multichannel mode (8 channels)
  • In Roon the Stereo playback is spit up to eight channels via an eight channel 64kTaps Convolution filter

Analysis

After the reboot this morning I observed memory usage with the “top -d 1” command on my 2GB Pi4.

  • Right after start 4.4%
  • Two hours later: 30%
  • Now 40%
  • Tendency still increasing

Same with htop filtered with “roon”

Summary

The behavior can be reproduced. Stopping Roon Bridge and restarting the service memory usage starts with low values and increases during playback over time till no more memory is available freezing the DietPi on 2GB Pi4

Best DrCWO

Hi @DrCWO,

Thanks for the detailed report and the memory usage data. We’ve asked QA to try reproducing this on our side.

Convolution is a very resource-intensive process, so this may not be far off. We’d be interested to hear whether the memory usage stabilizes or keeps increasing after more observation.

As far as I can see it increases. I now attached a monitor to see what happens at the next crash. Sa soon as I know more I will post.

Best DrCWO

Hi @noris,
is there a chance to get an elder release of Roon Bridge so I can install this and see if it behaves different?

Would be great so I can verify my findings.

Best DrCWO

I have some more findings :+1:

The bash script below limits the max memory usage allowed for RAATServer to 128MB.
It gets the PID of RAATServer and limits max allowed memory usage for this PID.

set -e

PROCESS="RAATServer"
CG="/sys/fs/cgroup/limited"
LIMIT=$((1024 * 1024 * 128)) 

# Find the process PID(s)
PIDS=$(pgrep -x "$PROCESS" || true)

if [ -z "$PIDS" ]; then
    echo "Error: Process '$PROCESS' not found."
    exit 1
fi

# Create the cgroup if it does not exist
if [ ! -d "$CG" ]; then
    sudo mkdir "$CG"
fi

# Set the memory limit
echo "$LIMIT" | sudo tee "$CG/memory.max" > /dev/null

# Move each matching process into the cgroup
while read -r PID; do
    echo "Limiting $PROCESS (PID $PID) to $LIMIT"
    echo "$PID" | sudo tee "$CG/cgroup.procs" > /dev/null
done <<< "$PIDS"

echo "Done."

It can be observed that the RAATServer consumes memory up to this limit.
Afterward, it was terminated and restarts with a new PID.

The limit can be set as high as you like. The higher the limit, the longer music can be streamed via RAAT before the RAATServer got terminated. With the limit of 128MB restart happens after some minutes playing back music.

This reinforces my assumption that this is a genuine memory leak.

Based on the rise in memory usage, I suspect it is the audio data that isn’t being released. With my eight channels, I see about 10 Mbit/s being sent to the Roon Bridge over the network, and memory consumption increases by approximately 1 MB per second. A nice coincidence.

Best DrCWO

Found an elder Roon Bridge on one of my saved SD-Cards for the Raspberry Pi:

 cat /opt/RoonBridge/VERSION
100801125
1.8 (build 1125) stable

Very small memory usage here. This completely proves my claim.
Probably the issue came in with the new .net release published some time ago.

Best DrCWO

I am also seeing this on some Pi 3b+ running DietPi(current-10.72) with RoonBridge 2.71(1683). The memory use for Raat is topping out around 423MB on one device and 223MB on another. These devices feed SMSL and Ifi Zen DACs over USB. A similar device feeding over HDMI got up to about 120MB before leveling off.

For what it is worth, I am also running RoonBridge 2.71 (1689) in my Gustard A26 (uses internal USB). It is not exactly apples to apples as the Gustard uses an ARM 7 (v7L), but Raat (1689) is acquiring and releasing resources as per normal with memory hovering around 38.8MB on this device.

You see if it’s only developing that way while playing or also without playing?

It seems to be steady after re-start while dormant over a few hours. Query with Settings>About in RoonRemote raises by a few bytes.

As soon as starting playback, it starts a fairly rapid and steady climb while passing a data stream of 25/192 flac. Stopping playback stops the rise, but RAAT holds the memory.

Playing mp3 was stable for a few minutes but then started gobbling resources.

Playing DSD only had a trivial increase, but changing to flac, wav, mp3, ogg started the climb, switching back to DSD stopped the growth, but memory was not cleared.

After playing DSD a while, the memory use creeps up slightly.

Hi again,
I guess I found a possible work around to stop the extreme memory consumption.

As RAATServer runs .NET 10 there are at luck environment variables that tell .NET to accept a limit for the heap :+1:

What to do:
Open the Linux bash as root and type:

systemctl stop roonbridge
systemctl disable roonbridge
nano /etc/systemd/system/roonbridge.service

Enter these two lines right behind the line saying [Service] and save the file.

Environment="DOTNET_GCHeapHardLimit=0x00400000"
Environment="DOTNET_GCConserveMemory=7"

After that again in the root bash:

systemctl enable roonbridge
systemctl start roonbridge

Those .NET variables set a hard limit to the .NET heap to 4MiB RAM.
In my case the memory consumption rises up to 279M and seems to stalls there.
This is what htop reports now:

It is still a lot but this limit seems to stop eating up all my RAM preventing other processes to run.
I hope this will be helpful for others too :slight_smile:

I will observe further and report …
Best DrCWO

It would have been too good to be true. Now I’m back to over 600MB :

Also immer noch keine Lösung. Das hier ist vielleicht interessant fpr die Roon Entwickler:

 awk '/^[0-9a-f]+-/ {map=$0} /^Rss:/ && $2>=32768 {printf "%s  RSS=%d MiB\n", map, $2/1024; n++} END {printf "Große Bereiche: %d\n", n}' /proc/47990/smaps
7ec8000000-7ecbffd000 rw-p 00000000 00:00 0   RSS=63 MiB
7ecc000000-7ecfff6000 rw-p 00000000 00:00 0   RSS=63 MiB
7ed0000000-7ed3ff8000 rw-p 00000000 00:00 0   RSS=63 MiB
7ed4000000-7ed7ff6000 rw-p 00000000 00:00 0   RSS=63 MiB
7ed8000000-7edbffe000 rw-p 00000000 00:00 0   RSS=63 MiB
7edc000000-7edfffd000 rw-p 00000000 00:00 0   RSS=63 MiB
7ee0000000-7ee3ffd000 rw-p 00000000 00:00 0   RSS=63 MiB
7ee4000000-7ee8000000 rw-p 00000000 00:00 0   RSS=64 MiB
7efc000000-7f00000000 rw-p 00000000 00:00 0   RSS=63 MiB
Große Bereiche: 9

My solution is so far:

  • Get all files of RoonBridge v1.8 from an old linux image from end of last year in a tar file
  • Uninstall RoonBridge using sudo ./roonbridge-installer-linuxarmv8.sh uninstall
  • Untar the saved files from the archive

With this I’m happily back on a RoonBridge v1.8 running with mono and without memory leak and stable 62568MB memory usage.

image

But this is NO SOLUTION for the Roon Community but only my personal workaround until Roon will fix it.

Best DrCWO

Thanks for the time and additional troubleshooting so far @DrCWO. As @noris mentioned above, our team has a ticket in for further investigation and to attempt reproduction internally.

We’ll share any updates or new information as the process continues on our end. Thanks for your patience in the meantime!

This is just a ping to keep the tread open :slight_smile:

Hi @DrCWO,

Thanks for checking in, and for all the detailed analysis. It’s all with our team, and our QA team is working on reproducing it.

One note on Roon Bridge 1.8: it’s a much older version from before Roon 2.0 and is no longer supported. It’s fine as a stopgap for now, but it won’t get fixes, and it may stop working with future Roon Server updates. Once the fix for this is released, please move back to the current Roon Bridge.

Since this is now with our development team, there’s no need to keep pinging the thread. We’ll mark it as ticketed and close it for now. If we need anything more from you, we’ll reopen it, and we’ll post here as soon as there’s a fix.