harden external-trigger watcher: polling backstop + periodic re-arm + health export#246
Merged
Merged
Conversation
… health export fs.watch on Linux can silently die (inotify queue overflow, inode rebind after dir recreation) with no error event and no observable signal. Three layers added: Layer 1 (pollInterval): setInterval at 30 s calls scanExisting(). The dispatched map makes re-scanning idempotent. Uses .unref() so it does not keep the process alive. Cleared in stopWatcher(). Layer 2 (rearmTimer): setInterval at 5 min closes and re-opens the fs.watch binding via a shared armWatcher() helper. Guarantees the inotify registration is never more than 5 min stale. Uses .unref(). Cleared in stopWatcher(). Layer 3 (getHealth): watcherLastEventMs tracks the timestamp of the last watcher callback (updated before the .json guard). getHealth() returns watcherAlive, lastEventMs, and pollActive for external monitoring. No new dependencies. All 309 existing tests pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fs.watch on Linux can silently die (inotify queue overflow, inode rebind after dir recreation) with no error event and no observable signal. Three hardening layers added to project-external-trigger.js:
Layer 1 - Polling backstop: A 30 s setInterval calls scanExisting() periodically. The dispatched map makes re-scanning idempotent. Uses .unref() so it does not keep the process alive. Cleared in stopWatcher().
Layer 2 - Periodic watcher re-arm: A 5 min setInterval closes and re-opens the fs.watch binding via a shared armWatcher() helper. Guarantees the inotify registration is never more than 5 min stale. Uses .unref(). Cleared in stopWatcher().
Layer 3 - Health export: watcherLastEventMs tracks the timestamp of the last watcher callback (updated before the .json filename guard). getHealth() returns watcherAlive, lastEventMs, and pollActive for external monitoring.
No new dependencies. Pure Node stdlib. All 309 existing tests pass.