Skip to content

Optimize inotify watches and add error handling#6

Closed
assisted-by-ai wants to merge 0 commit intoKicksecure:masterfrom
assisted-by-ai:claude/fix-file-watcher-limit-0ktc9
Closed

Optimize inotify watches and add error handling#6
assisted-by-ai wants to merge 0 commit intoKicksecure:masterfrom
assisted-by-ai:claude/fix-file-watcher-limit-0ktc9

Conversation

@assisted-by-ai
Copy link
Copy Markdown

Summary

Improved inotify watch setup by replacing broad event monitoring with a targeted mask and added error handling for watch creation failures.

Key Changes

  • Optimized inotify event mask: Replaced pyinotify.ALL_EVENTS with a specific watch_mask containing only the events actually handled by INotifyEventHandler (IN_MODIFY, IN_CREATE, IN_DELETE, IN_MOVED_FROM, IN_MOVED_TO, IN_DELETE_SELF, IN_MOVE_SELF). This reduces unnecessary inotify resource consumption from unprocessed events like IN_ACCESS, IN_OPEN, and IN_CLOSE_NOWRITE.

  • Added error handling: Implemented validation of add_watch() return values for all three watch paths (tor_path, torrc_path, sdwdate_status_path). Failed watches (indicated by negative watch descriptors) are now logged as errors.

  • Removed recursive watching: Removed the rec=True parameter from add_watch() calls, simplifying the watch configuration.

  • Added .gitignore: Added __pycache__/ to .gitignore to exclude Python cache directories from version control.

Implementation Details

The add_watch() method returns a dictionary mapping paths to watch descriptors. Watch descriptors less than 0 indicate failures, which are now properly detected and logged for debugging purposes.

https://claude.ai/code/session_019HiJXyxtYfp1BQDgAPjEqd

Copy link
Copy Markdown
Contributor

@ArrayBolt3 ArrayBolt3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted with tweaks in ArrayBolt3@32edffb.

Comment on lines +519 to +531
## Only watch for events that are actually handled by INotifyEventHandler.
## Using ALL_EVENTS would waste inotify resources on events like IN_ACCESS,
## IN_OPEN, IN_CLOSE_NOWRITE, etc. that are never processed.
watch_mask: int = (
pyinotify.IN_MODIFY
| pyinotify.IN_CREATE
| pyinotify.IN_DELETE
| pyinotify.IN_MOVED_FROM
| pyinotify.IN_MOVED_TO
| pyinotify.IN_DELETE_SELF
| pyinotify.IN_MOVE_SELF
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted, but the comment isn't necessary.

Comment on lines +525 to +565
GlobalData.watch_manager.add_watch(
ret: dict[str, int] = GlobalData.watch_manager.add_watch(
GlobalData.tor_path,
pyinotify.ALL_EVENTS,
rec=True,
watch_mask,
)
GlobalData.watch_manager.add_watch(
for path, wd in ret.items():
if wd < 0:
logging.error(
"Failed to add inotify watch for '%s'!", path,
)
ret = GlobalData.watch_manager.add_watch(
GlobalData.torrc_path,
pyinotify.ALL_EVENTS,
rec=True,
watch_mask,
)
for path, wd in ret.items():
if wd < 0:
logging.error(
"Failed to add inotify watch for '%s'!", path,
)
if found_sdwdate_path:
GlobalData.watch_manager.add_watch(
ret = GlobalData.watch_manager.add_watch(
GlobalData.sdwdate_status_path,
pyinotify.ALL_EVENTS,
watch_mask,
)
for path, wd in ret.items():
if wd < 0:
logging.error(
"Failed to add inotify watch for '%s'!", path,
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted, but refactored to be less repetitive.

Comment thread .gitignore
@@ -0,0 +1 @@
__pycache__/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted.

@assisted-by-ai assisted-by-ai force-pushed the claude/fix-file-watcher-limit-0ktc9 branch from b4cc199 to e0deac3 Compare April 27, 2026 18:30
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.

2 participants