Neo4j Error: Too many open files
Root Cause
Neo4j was hitting the system file descriptor limit of 60,000.
io.netty.channel.unix.Errors$NativeIoException: accept(..) failed: Too many open files
Key Discovery: Two Neo4j Processes
Neo4j runs as two separate Java processes:
- Boot/Launcher process (PID 143758) - minimal usage (~450 files)
- Database engine process (PID 143802) - heavy usage (~60,000 files)
Analysis
systemctl status neo4j
only shows the main PID (143758):
$ sudo systemctl status neo4j ● neo4j.service - Neo4j Graph Database Loaded: loaded (/usr/lib/systemd/system/neo4j.service; enabled; preset: disabled) Drop-In: /etc/systemd/system/neo4j.service.d └─override.conf Active: active (running) since Thu 2025-06-26 08:48:23 UTC; 3 weeks 5 days ago Main PID: 143758 (java) Tasks: 220 (limit: 1645996) Memory: 245.6G CPU: 1d 22h 1min 20.208s CGroup: /system.slice/neo4j.service
The usage for main PID seems to be within limits:
$ sudo ls /proc/143758/fd | wc -l 450
lsof -u neo4j
shows that the user neo4j
runs two processes (143758 and 143802):
$ lsof -u neo4j COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME java 143758 neo4j cwd unknown /proc/143758/cwd (readlink: Permission denied) java 143758 neo4j rtd unknown /proc/143758/root (readlink: Permission denied) java 143758 neo4j txt unknown /proc/143758/exe (readlink: Permission denied) java 143758 neo4j NOFD /proc/143758/fd (opendir: Permission denied) java 143802 neo4j cwd unknown /proc/143802/cwd (readlink: Permission denied) java 143802 neo4j rtd unknown /proc/143802/root (readlink: Permission denied) java 143802 neo4j txt unknown /proc/143802/exe (readlink: Permission denied) java 143802 neo4j NOFD
The second PID (143802) has Max open files
limits of 60,000:
$ cat /proc/143802/limits Limit Soft Limit Hard Limit Units Max cpu time unlimited unlimited seconds Max file size unlimited unlimited bytes Max data size unlimited unlimited bytes Max stack size 8388608 unlimited bytes Max core file size unlimited unlimited bytes Max resident set unlimited unlimited bytes Max processes 1028747 1028747 processes Max open files 60000 60000 files Max locked memory 8388608 8388608 bytes Max address space unlimited unlimited bytes Max file locks unlimited unlimited locks Max pending signals 1028747 1028747 signals Max msgqueue size 819200 819200 bytes Max nice priority 0 0 Max realtime priority 0 0 Max realtime timeout unlimited unlimited us
The usage for the second PID (143802) is almost at the limit:
$ sudo ls /proc/143802/fd | wc -l 59995
Fix
Increase systemd
service limits to allow more open files:
sudo systemctl edit neo4j
Add to override file:
[Service] LimitNOFILE=1048576 LimitNPROC=65536
Reload the service config:
sudo systemctl daemon-reloaj
To apply the changes to the running processes immediately without a restart, use command prlimit
to increase limits:
sudo prlimit --pid 143758 --nofile=1048576:1048576 sudo prlimit --pid 143802 --nofile=1048576:1048576