Skip to content

Replace inotifywait with polling in cgroup cleanup#37

Open
assisted-by-ai wants to merge 1 commit intoKicksecure:masterfrom
assisted-by-ai:claude/fix-inotifywait-enospc-ve1mb
Open

Replace inotifywait with polling in cgroup cleanup#37
assisted-by-ai wants to merge 1 commit intoKicksecure:masterfrom
assisted-by-ai:claude/fix-inotifywait-enospc-ve1mb

Conversation

@assisted-by-ai
Copy link
Copy Markdown

Summary

Refactored the cgroup cleanup logic to use polling instead of inotifywait, eliminating dependency on the kernel's limited inotify watch pool and preventing ENOSPC errors on watch-constrained systems.

Key Changes

  • Replaced inotifywait-based event monitoring with a simple polling loop that checks cgroup.events up to 50 times
  • Removed file descriptor management and subshell complexity associated with inotifywait
  • Simplified variable declarations by removing inotifywait_subshell_pid and inotifywait_fd, replacing with cgroup_drained and poll_count
  • Added timeout detection with warning log when cgroup fails to drain within the polling limit
  • Moved cgroup.kill write before the polling loop (more logical flow)
  • Maintained the same 0.1 second sleep interval between polls for consistent behavior

Implementation Details

  • The polling approach is viable because cgroup.kill sends SIGKILL, so draining is near-instant
  • Maximum wait time is ~5 seconds (50 polls × 0.1 second sleep)
  • Cleaner error handling with explicit cgroup_drained flag instead of relying on subshell exit status
  • Reduced kernel resource consumption by eliminating inotify watch usage

https://claude.ai/code/session_01V4XkxCqroKpfDZE2Jknmdx

…trained systems

inotifywait consumes an inotify watch from the kernel's limited
fs.inotify.max_user_watches pool, which can cause "ENOSPC: System limit
for number of file watchers reached" on systems where other software
(IDEs, file managers, etc.) already uses many watches.

Replace with a polling loop (50 iterations * 0.1s = 5s timeout). Since
cgroup.kill sends SIGKILL, draining should be near-instant, making
polling perfectly adequate. This also fixes:
- no timeout (script could hang forever if cgroup never drained)
- no error handling if inotifywait failed to start
- potential leaked inotifywait processes on signal interruption

https://claude.ai/code/session_01V4XkxCqroKpfDZE2Jknmdx
@ArrayBolt3
Copy link
Copy Markdown
Contributor

Accepted in ArrayBolt3@36e9838.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants