Troubleshooting Linux Electron Debug Crash (ENOSPC: System limit for number of file watchers reached)
1. Symptoms and Root Cause Analysis (RCA)
When running the SyncETA Electron application in debug mode (yarn dev:debug) in a Linux desktop development environment, the Vite/Chokidar file watcher monitors file descriptors inside node_modules and workspace subdirectories. This exceeds the Linux kernel's default inotify watcher limit (8192 or 65536), causing the process to terminate abnormally with an ENOSPC: System limit for number of file watchers reached exception.
2. Solution 1: Increase the Linux Kernel inotify Watcher Limit (Recommended)
2.1 Check Current Kernel Values
cat /proc/sys/fs/inotify/max_user_watches
cat /proc/sys/fs/inotify/max_user_instances2.2 Apply Immediately at Runtime (Temporary)
sudo sysctl fs.inotify.max_user_watches=524288
sudo sysctl fs.inotify.max_user_instances=10242.3 Apply Permanently (/etc/sysctl.d/99-inotify.conf)
Register a sysctl.d configuration file so that the settings persist across system reboots.
echo 'fs.inotify.max_user_watches=524288' | sudo tee /etc/sysctl.d/99-inotify.conf
echo 'fs.inotify.max_user_instances=1024' | sudo tee -a /etc/sysctl.d/99-inotify.conf
sudo sysctl -p /etc/sysctl.d/99-inotify.confAfter applying the configuration, re-run yarn dev:debug to verify normal startup.
3. Solution 2: Switch to Polling Mode When Kernel Parameters Cannot Be Modified (Containers / Restricted Environments)
In CI container environments without sudo privileges or where modifying kernel parameters is restricted, enable polling mode instead of relying on filesystem events.
3.1 One-Time Environment Variable Execution
CHOKIDAR_USEPOLLING=1 CHOKIDAR_INTERVAL=800 yarn dev:debug3.2 Register in IDE Run/Debug Configuration
You can apply these settings permanently in IntelliJ IDEA by adding the following variables under Run/Debug Configurations -> Environment variables:
| Environment Variable Key | Recommended Value | Description |
|---|---|---|
CHOKIDAR_USEPOLLING | 1 | Enables periodic file state polling instead of OS kernel inotify |
CHOKIDAR_INTERVAL | 800 | File change detection polling interval (in ms, minimizing CPU overhead) |