Skip to content

fs: prevent spurious recursive watch events on prefix siblings - #63095

Merged
nodejs-github-bot merged 3 commits into
nodejs:mainfrom
marcopiraccini:rename-watch-fix
Jun 9, 2026
Merged

fs: prevent spurious recursive watch events on prefix siblings#63095
nodejs-github-bot merged 3 commits into
nodejs:mainfrom
marcopiraccini:rename-watch-fix

Conversation

@marcopiraccini

@marcopiraccinimarcopiraccini commented May 3, 2026

Copy link
Copy Markdown
Contributor

Fix a bug in the JS-based recursive fs.watch (used on Linux) where deleting an entry caused spurious rename events to be emitted for unrelated sibling entries whose names share a prefix with the deleted entry.

FSWatcher#unwatchFiles(file) in lib/internal/fs/recursive_watch.js used StringPrototypeStartsWith(filename, file) to find the watched entries to remove. This match is a raw string prefix, so deleting foo also unwatched foo_, foo_bar, foo_bar/file.txt, and so on. The next time #watchFolder walked the parent directory, those still-on-disk siblings were missing from #files and were treated as newly created, firing extra rename events and re-attaching watchers redundantly.

Fix

Match by exact path, or by deletedPath + path.sep prefix, so only the deleted entry and its actual descendants are unwatched.

Fixes: #58868

@nodejs-github-botnodejs-github-bot added fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run. labels May 3, 2026
@marcopiraccini
marcopiraccini marked this pull request as ready for review May 3, 2026 08:25
@codecov

codecovBot commented May 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.33%. Comparing base (837910d) to head (430d3a4).
⚠️ Report is 165 commits behind head on main.

Additional details and impacted files
@@ Coverage Diff @@## main #63095 +/- ##
========================================
Coverage 90.33% 90.33% ========================================
Files 730 730 Lines 234205 234365 +160 Branches 43927 43927 ========================================
+ Hits 211559 211714 +155 + Misses 14370 14368 -2 - Partials 8276 8283 +7 
Files with missing linesCoverage Δ
lib/internal/fs/recursive_watch.js87.11% <100.00%> (+1.84%)⬆️

... and 44 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.

@mcollinamcollina added the request-ci Add this label to start a Jenkins CI on a PR. label May 19, 2026

@mcollinamcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label May 19, 2026
@nodejs-github-bot

This comment was marked as outdated.

@mcollinamcollina added the request-ci Add this label to start a Jenkins CI on a PR. label May 24, 2026
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label May 24, 2026
@nodejs-github-bot

This comment was marked as outdated.

Signed-off-by: marcopiraccini <marco.piraccini@gmail.com>
Signed-off-by: marcopiraccini <marco.piraccini@gmail.com>

@mcollinamcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@mcollinamcollina added the request-ci Add this label to start a Jenkins CI on a PR. label May 31, 2026
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 1, 2026
@nodejs-github-bot

This comment was marked as outdated.

@ShogunPandaShogunPanda added the request-ci Add this label to start a Jenkins CI on a PR. label Jun 8, 2026
@github-actionsgithub-actionsBot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 8, 2026
@nodejs-github-bot

This comment was marked as outdated.

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@trivikrtrivikr added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Jun 9, 2026
@nodejs-github-botnodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jun 9, 2026
@nodejs-github-bot
nodejs-github-bot merged commit 716a92e into nodejs:mainJun 9, 2026
85 checks passed
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Landed in 716a92e

aduh95 pushed a commit that referenced this pull request Jun 18, 2026
Signed-off-by: marcopiraccini <marco.piraccini@gmail.com>
PR-URL: #63095Fixes: #58868
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
aduh95 pushed a commit that referenced this pull request Jun 25, 2026
Signed-off-by: marcopiraccini <marco.piraccini@gmail.com>
PR-URL: #63095Fixes: #58868
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
aduh95 pushed a commit that referenced this pull request Jul 30, 2026
Signed-off-by: marcopiraccini <marco.piraccini@gmail.com>
PR-URL: #63095Fixes: #58868
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.commit-queue-squashAdd this label to instruct the Commit Queue to squash all the PR commits into the first one.fsIssues and PRs related to the fs subsystem / file system.needs-ciPRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fs.watch recursive on Linux emits spurious rename events for sibling files/directories prefixed by related paths on deletion

5 participants

@marcopiraccini@nodejs-github-bot@mcollina@ShogunPanda@trivikr