Okay guys, I've been dealing with this issue off and on for a WHILE. I just solved it.
For me, the issue was down to UNRAID's extremely low open file limit. ulimit -n would return something like 40k which for my specific use case was NOT enough.
Running ulimit -s N (where N is the desired value) actually doesn't help anything because shfs is already running and has the tiny file descriptor limit. I wrote this script which increases the limit for all running shfs processes (parent and child). This makes it so the shares do not drop out when the maximum open files limit is reached.
#!/bin/bash
# Function to set ulimit -n for child processes
function set_ulimit_for_children() {
local parent_pid=$1
local limit=$2
# Get the list of child PIDs from pstree output
local child_pids=$(pstree -p $parent_pid | grep -oE '[0-9]+')
# Iterate over the child PIDs and set ulimit -n for each child process
for child_pid in $child_pids; do
# Skip the parent PID
if [ "$child_pid" != "$parent_pid" ]; then
echo "Increasing ulimit -n for PID $child_pid"
prlimit --pid $child_pid --nofile=$limit
fi
done
}
# Set the desired ulimit -n value
limit=1048576 # A million is a lot of open files
# Get PIDs for any instances of "/usr/local/sbin/shfs"
parent_pids=$(pgrep -f "/usr/local/sbin/shfs")
# Iterate over all instances of "/usr/local/sbin/shfs"
for parent_pid in $parent_pids; do
# Check if the parent process exists
if ! kill -0 $parent_pid > /dev/null 2>&1; then
echo "No running /usr/local/sbin/shfs process found with PID $parent_pid."
exit 1
fi
# Set ulimit -n for the parent process
echo "Increasing ulimit -n for PID $parent_pid"
prlimit --pid $parent_pid --nofile=$limit
# Call the function to set ulimit -n for child processes
set_ulimit_for_children $parent_pid $limit
done