Quick Summary: Troubleshooting a silent rsync --delete hang inside a container, specifically when dealing with overlayfs and high file counts. Discover the obscu...Alright, listen up. If you've ever pulled your hair out trying to figure out why your
rsync --delete command just... *stops*... without erroring, especially inside a container on an overlayfs mount, you're not alone. I've been there. This isn't your garden-variety network timeout or disk full error. This is a subtle, insidious beast that will waste days of your life if you don't know exactly where to look.We're talking about a silent hang.
rsync just sits there, CPU usage near zero, no IO wait, strace showing it stuck on inotify_add_watch. It's infuriating. You'll check network, disk, memory, dmesg – everything looks fine. But your sync isn't moving.This specific flavor of hell usually manifests under a very particular set of conditions. Pay attention.
| Category | Specifics Where Error Triggers |
|---|---|
| Operating System | Linux (Ubuntu 18.04/20.04, CentOS 7/8, Debian 10/11) |
| Kernel Version | 4.x - 5.10 (especially older 4.x kernels); less prevalent on 5.11+ due to inotify subsystem improvements |
| Container Runtime | Docker (any version), containerd, Podman; running on cgroupv1 enabled hosts |
| Filesystem | overlayfs (typically Docker's default storage driver for layers) |
rsync Flags |
--delete, --archive (-a), --recursive (-r) on large directories (>10k files) |
| Workload Type | Synchronizing directories with many subdirectories and files, especially those with high churn (create/delete) |
dmesg for OOMs or obscure kernel errors, right? You've looked at strace for EINTR or EAGAIN? Good. Because this isn't any of that. This is deeper.You likely ran
rsync -avz --delete source/ destination/ and it just... froze. What gives?The diagnostic path starts with
strace. Attach strace -p <rsync_pid> to your hung rsync process. You'll probably see something like:inotify_add_watch(9, "/path/to/some/deep/directory", IN_ATTRIB|IN_CREATE|IN_DELETE|IN_DELETE_SELF|IN_MODIFY|IN_MOVE_SELF|IN_MOVED_FROM|IN_MOVED_TO|IN_DONT_FOLLOW|IN_EXCL_UNLINK|IN_ONLYDIR) = -1 ENOSPC (No space left on device)Wait,
ENOSPC? But your disk isn't full! This is the misleading part. ENOSPC here doesn't mean disk space. It means you've hit the system-wide limit for inotify watches.The Root Cause
Here's the ugly truth:rsync --delete needs to do a lot of bookkeeping. It often uses inotify to track changes efficiently, especially when dealing with --delete to figure out what files are gone. inotify is great for watching a few directories. It's terrible when asked to watch *tens of thousands* of individual directories, which rsync -r can easily do on a large, deep filesystem tree.Combine this with
overlayfs. Each layer in overlayfs can add to the inotify count. Docker containers, by default, often run on overlayfs. When rsync traverses a huge directory tree with overlayfs, it can quickly exhaust the default kernel inotify limits.Crucially, in
cgroupv1 environments (still very common in production), resource isolation for inotify descriptors isn't as granular as you'd like. The fs.inotify.max_user_watches sysctl parameter is a *system-wide* limit. If one container, or even one user process, is aggressively consuming inotify watches, it can starve others. And rsync --delete is an absolute hog. This is similar to how "The Ghost in the UDP Socket" often discusses subtle kernel-level resource exhaustion manifesting as unexpected behavior.Your
ulimit -n (max open files) might be high, but inotify watches aren't regular file descriptors in the same way. While they consume FDs, their *count* is governed by a separate sysctl limit, fs.inotify.max_user_watches. The ENOSPC error is the kernel's way of saying "I can't allocate more inotify objects, even if you have file descriptor space."
1. Check Current
inotify Limits:Inside your container *and* on the host, run:
sysctl fs.inotify.max_user_watchessysctl fs.inotify.max_queued_eventssysctl fs.inotify.max_user_instancesYou'll probably see
max_user_watches at default values (e.g., 8192 or 16384). For large rsync operations, this is laughably low.2. Increase
inotify Limits:This must be done on the HOST system, as
inotify limits are a kernel-wide resource. Restarting a container won't help if the host is constrained.Edit
/etc/sysctl.conf and add/modify these lines:
fs.inotify.max_user_watches = 524288
fs.inotify.max_user_instances = 1024
fs.inotify.max_queued_events = 32768
Apply with:
sudo sysctl -p
Yes, those numbers look high. They *are* high. But for environments with many containers and heavy
inotify users, they're often necessary. Adjust max_user_watches based on your total file count across all rsync operations. Think about how many *directories* are being watched.3. Rethink
rsync Flags (If Possible):If increasing host
inotify limits isn't an immediate option or you're hitting other resource walls (like a potential scenario described in ZenithRuntime v0.2.1: The Kernel-Bypass Dream or a Production Nightmare? where kernel-level interactions can become pathological), consider modifying your rsync command.*
--no-inc-recursive: This forces rsync to do a full scan of directories instead of trying to optimize with inotify or other incremental tricks. It's slower, but avoids the inotify trap.
* --inplace: If files are large and network isn't an issue, this can sometimes reduce the temporary file churn that rsync might otherwise perform, potentially alleviating some FD pressure, though it doesn't directly solve the inotify issue.
* Break it up: Can you rsync smaller subdirectories individually? This reduces the concurrent inotify watch count.4. Verify
ulimit -n for the rsync process:Though less likely the *primary* cause of the
ENOSPC on inotify_add_watch, ensure the ulimit -n for the user running rsync inside the container is sufficiently high (e.g., 65536). You can set this in daemon.json for Docker or via systemd unit files.This isn't a silver bullet for *all*
rsync hangs, but it's the one that will make you question your life choices if you don't catch it. Incrementally increasing fs.inotify.max_user_watches on the host, then restarting your container, should resolve the silent hang.Go forth and sync, but with your eyes wide open to these hidden kernel traps. Don't let a poorly documented
ENOSPC steal your weekend.
Comments
Post a Comment