Ubuntu 18.04.2 LTS - Plex Server Crashes - Double free or corruption (!prev)

Thank you - i think we have plenty of dumps and logs now for the double free issue. Just need to wait now for the development team

1 Like

Any updates on this issue?

Or maybe a workaround so I can let systemd restart the service automatically when this happens?

I made a script that checks syslog if Plex has crashed, takes a backup of Plex logs and restarts the service.

Set up a cronjob to run the script, average downtime 1-2 min when Plex crashes.

Had 2 crashes past 7 days.

Can you share the script and your cron settings? I believe someone else said they also changed something to prevent the plex relay service from running and that also stopped them as the issue is with the plex relay.

Because FreeNAS can only do one thing? FreeBSD has had Jails since 2000. There are plenty of people running all their task as Jails because it is easy to sandbox them and modularize them. Jail mechanism is basically the grandfather of Docker.

Here’s what I’m doing.

I’m on Ubuntu Server 18.04.2

Create the following file:
sudo nano /bin/watch-server

#!/bin/bash

service=$@
/bin/systemctl -q is-active "$service.service"
status=$?
if [ "$status" == 0 ]; then
    echo "OK"
else
    /bin/systemctl restart "$service.service"
fi

Create a cronjob with:
sudo crontab -e

I set mine to run this script every two minutes:

# Ensure PlexMediaServer is running
2 * * * * /bin/watch-server plexmediaserver > /dev/null

ctrl-x and save
And that’s it.

(Credit to: https://maslosoft.com/kb/watching-for-service-with-cron/)

1 Like

But with the crash that’s occurring the status does not change for the service. That is the problem most people are having. The other user said they check syslog to see if the crash has occurred I would assume looking for the Double Free error it generates.

Here is my quick and dirty script for restarting Plex if it crashes, while this issue is being fixed.

Quick overview of script:

  1. Check if syslog contains the string “PLEX MEDIA SERVER CRASHED”
  2. If server has crashed, then let’s enforce logrotate so this doesn’t loop if Plex crashes (you might want to reconsider another way if you don’t want unexpected logrotate), but I don’t mind because Plex does not crash that often, if Plex would crash multiple times a day then I would likely implement another way.
  3. Create a new folder for backup of Plex log when it crashes. I use the timestamp as a folder which would make it unique.
  4. Copy all logs if I would want to review them at any point, I use rsync.

crash logs will typically be removed the next time Plex Media Server is launched
https://support.plex.tv/articles/201455336-crash-logs-plex-media-server/#toc-2

  1. Restart the service

Script:

#!/bin/bash

hasCrashed="$(grep "PLEX MEDIA SERVER CRASHED" /var/log/syslog | wc -l)"

dumpDir=/somepath/plexdump/$(date +%s)/

if [[ "$hasCrashed" != "0" ]]; then
	/usr/sbin/logrotate -f /etc/logrotate.conf
	mkdir -p $dumpDir
	rsync -av /var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server/Logs $dumpDir
	rsync -av /var/lib/plexmediaserver/Library/Application\ Support/Plex\ Media\ Server/Crash\ Reports $dumpDir
	/bin/systemctl restart plexmediaserver.service
	echo "Plex has CRASHED"
fi

Crontab:

* * * * * /usr/local/bin/plexWatcher.sh >/dev/null 2>&1

I run this every minute with a cronjob


Checking if the service is active would not work for me, because the service is still reported as active when Plex crashes.

2 Likes

Yup, you’re totally right! haha, thanks

I’m rather new to Linux and not sure if this is working. I don’t care about saving the logs as for now they have enough so I removed those entries from the file so I have

#!/bin/bash

hasCrashed="$(grep "PLEX MEDIA SERVER CRASHED" /var/log/syslog | wc -l)"

if [[ "$hasCrashed" != "0" ]]; then
        /usr/sbin/logrotate -f /etc/logrotate.conf
        /bin/systemctl restart plexmediaserver.service
        echo "Plex has CRASHED"
fi

The files name and location is /bin/plexwatcher.sh

I then CHOWN the file from root root to my user I login to the VM as and gave it rwx permissions.

Then created the Crontab as

* * * * * /bin/plexwatcher.sh >/dev/null 2>&1

Now when I run cat /var/log/syslog | grep cron it doesn’t show that job running. Just that crontab reloaded after modifying it.

Is it running and just not reporting it is? Have I messed something up?

Edit: I tried moving it to /usr/local/bin and chown back to root:root and I still don’t show that it’s running. The script seems to run if I execute it directly but doesn’t run with the Cron or at least isn’t displaying that it is.

You should be all set, the cronjob should fire every minute now, if it finds the string “PLEX MEDIA SERVER CRASHED” then it should log rotate and restart Plex.

If you would any indication that the script is actually being run then you could temporarily add something like:

#!/bin/bash

hasCrashed="$(grep "PLEX MEDIA SERVER CRASHED" /var/log/syslog | wc -l)"

if [[ "$hasCrashed" != "0" ]]; then
        /usr/sbin/logrotate -f /etc/logrotate.conf
        /bin/systemctl restart plexmediaserver.service
        echo "Plex has CRASHED"
fi

echo "I ran Plex watcher $(date)" >> /var/tmp/plex.watcher.log

e.g. the last line, it will add that line to the file plex.watcher.log, try adding that line to your script temporarily and check that file was created and contains any content.

This should help you, if you want to make sure your script is being run. Then just tail the file and wait a little.

touch /var/log/plex.watcher.log
tail -f /var/log/plex.watcher.log

Hope this helps :slightly_smiling_face:

1 Like

Ah ok I didn’t realize it would not log it running in the cron logs.

@sa2000 has there been an update from the dev team on this?

Any news about this issue? I also have this problem, however it is interesting that I have 2 servers, and only one of them crashes. Plex version is 1.15.5.994 on both, systems are Ubuntu 18.04.2 LTS of course. I’ve just updated ubuntu from 17.10 few weeks ago, and the problem started only after the update.

If you need any detail that you think might help solving the issue, then ask :slight_smile:

#!/bin/bash

hasCrashed="$(journalctl -r | grep 'PLEX MEDIA SERVER CRASHED' | wc -l)"

if [[ "$hasCrashed" != "0" ]]; then
        /bin/journalctl --rotate
        /bin/journalctl --vacuum-time=1s
        /bin/systemctl restart plexmediaserver.service
        echo "Plex has CRASHED"
fi

For anyone using Arch or a distro that uses journalctl instead of standard logs, I edited haukur46’s script to work. Journalctl should still archive the logs so this should be a proper way to handle this. For the cronjob either use systemd/timers or cronie off the official repos.

For cronie all that needs to be done is:

pacman -S cronie
systemctl start cronie.service
systemctl enable cronie.service
export EDITOR=/usr/bin/nano
crontab -e
* * * * * /bin/plexwatcher.sh >/dev/null 2>&1
1 Like

Why not just downgrade until this issue is resolved instead of using scripts to check logs and then restart Plex? Sounds like they have enough core dumps/logs, I downgraded to 1.14.1.5488 and it has been rock solid. The .15 jump obviously had too many changes to the code and there are some residual issues popping up.

Disappointed to see that today’s plex pass release did not contain a fix for this.

Any update on this would be appreciated.

1 Like

Honestly this has been an issue for 3 months it’s a bit ridiculous it hasn’t been fixed. At the very least they should try to fix the systemD service so it resets itself when it crashes so we don’t have to deal with this.

1 Like

I have escalated this.

I managed to get crashes which appear similar by having a looping slideshow of a tiny video (500 ms) that needs to be transcoded and a photo and after 4 to 12 hours it would crash. This needs now to be run by the development team in a debug environment

1 Like

That sounds like a Ubuntu thing? I’m running CentOS 7, using the default Plex systemd service file, and mine has always automatically restarted Plex after these ‘double free’ crashes. I didn’t have to do anything to get it to do that.

I’m using Arch not Ubuntu, others are having similar issues to me above it has to deal with the Plex relay binary.