Skip to content

watch: detect files replaced via unlink and create - #63888

Open
marcopiraccini wants to merge 2 commits into
nodejs:mainfrom
marcopiraccini:watch-monitor-replaced-files
Open

marcopiraccini wants to merge 2 commits into
nodejs:mainfrom
marcopiraccini:watch-monitor-replaced-files

Conversation

@marcopiraccini

@marcopiraccini marcopiraccini commented Jun 13, 2026 •

Copy link
Copy Markdown
Contributor

Fixes: #51621
Refs: #54774

On Linux, --watch stopped restarting after the first time a watched file was replaced via unlink+create or rename (atomic saves, docker compose watch, bind mounts), so it appeared to "only reload the first time".

filterFile watched each file directly, which binds the inotify watch to the file's inode.
On replacement the old inode is unlinked: the watch fires once, then dies; the new file's inode is never watched.

Fix: on Linux, watch the parent directory non-recursively instead of the file. The directory inode is stable across replacements, and unrelated siblings are still discarded by the filter-mode check in #onChange. macOS/Windows already watched the directory and were unaffected.

Other platforms without recursive watching (AIX, SmartOS, BSDs) keep watching the file itself: a directory watch there does not report the changed entry, which made the test time out on AIX and SmartOS.

@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Jun 13, 2026
@marcopiraccini
marcopiraccini marked this pull request as ready for review June 13, 2026 10:49
@mstaicu

mstaicu commented Aug 7, 2026

Copy link
Copy Markdown

When can we expect this to be merged?

@trivikr trivikr added watch-mode Issues and PRs related to watch mode. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. author ready PRs with CI started, the required approvals, and no outstanding review comments. labels Aug 21, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Aug 21, 2026
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

This comment has been minimized.

@trivikr trivikr removed the author ready PRs with CI started, the required approvals, and no outstanding review comments. label Aug 22, 2026
@trivikr

trivikr commented Aug 22, 2026

Copy link
Copy Markdown
Member

CI is failing on aix and smartos

not ok 5496 parallel/test-watch-mode-files_watcher
  ---
  duration_ms: 120070.78700
  severity: fail
  exitcode: -15
  stack: |-
    timeout
  ...

@codecov

codecov Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.44%. Comparing base (8812357) to head (17c0d62).
⚠️ Report is 9 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #63888      +/-   ##
==========================================
+ Coverage   90.36%   90.44%   +0.07%     
==========================================
  Files         790      790              
  Lines      274292   274508     +216     
  Branches    52510    53079     +569     
==========================================
+ Hits       247874   248275     +401     
+ Misses      16901    16754     -147     
+ Partials     9517     9479      -38     
Files with missing lines Coverage Δ
lib/internal/watch_mode/files_watcher.js 90.55% <100.00%> (-0.89%) ⬇️

... and 43 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@marcopiraccini
marcopiraccini force-pushed the watch-monitor-replaced-files branch from 8b2094b to fbf6b2d Compare September 19, 2026 11:47
@ShogunPanda ShogunPanda added the request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. label Sep 21, 2026
Signed-off-by: marcopiraccini <marco.piraccini@gmail.com>
Signed-off-by: marcopiraccini <marco.piraccini@gmail.com>
@marcopiraccini
marcopiraccini force-pushed the watch-monitor-replaced-files branch from fbf6b2d to 17c0d62 Compare September 26, 2026 03:02
@marcopiraccini

marcopiraccini commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor Author

@ShogunPanda @trivikr the request-ci label added on 2026-09-21 was never picked up: auto-start-ci only starts PRs with an approval, and the previous one was dismissed by the rebase. Could you re-review so Jenkins runs on AIX and SmartOS?

NOTE: make lint-js currently fails until #66307 lands

@panva panva closed this Sep 26, 2026
@panva panva reopened this Sep 26, 2026
@panva panva added the commit-queue-squash PRs the Commit Queue should land as one squashed commit. label Sep 26, 2026
@panva panva added author ready PRs with CI started, the required approvals, and no outstanding review comments. and removed request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Sep 26, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

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

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. commit-queue-squash PRs the Commit Queue should land as one squashed commit. needs-ci PRs that need a full CI run. watch-mode Issues and PRs related to watch mode.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--watch should monitor replaced files

6 participants