Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursive fs.watch crashes on Linux when deleting files #52018

Closed
maksis opened this issue Mar 8, 2024 · 6 comments · Fixed by #52349
Closed

Recursive fs.watch crashes on Linux when deleting files #52018

maksis opened this issue Mar 8, 2024 · 6 comments · Fixed by #52349
Labels
fs Issues and PRs related to the fs subsystem / file system. linux Issues and PRs related to the Linux platform. lts-watch-v20.x PRs that may need to be released in v20.x

Comments

@maksis
Copy link

maksis commented Mar 8, 2024

Version

v21.7.0

Platform

Linux ARCH-FS 6.7.8-arch1-1 #1 SMP PREEMPT_DYNAMIC Sun, 03 Mar 2024 00:30:36 +0000 x86_64 GNU/Linux

Subsystem

fs

What steps will reproduce the bug?

Run the following code on Linux:

const fs = require('fs')

try {
  fs.mkdirSync('./parent/child', { recursive: true })
} catch (e) {
  console.error(e)
}

fs.writeFileSync('./parent/child/test.tmp', 'test')

fs.watch('./parent', { recursive: true }, (eventType, filename) => {
  console.log(eventType, filename)
})

fs.rmSync('./parent/child/test.tmp')

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior? Why is that the expected behavior?

Emit a watcher event

What do you see instead?

Error: ENOENT: no such file or directory, stat '/home/maksis/parent/child/test.tmp'
    at statSync (node:fs:1659:25)
    at FSWatcher.<anonymous> (node:internal/fs/recursive_watch:160:28)
    at FSWatcher.emit (node:events:519:28)
    at FSWatcher._handle.onchange (node:internal/fs/watchers:215:12) {

Additional information

No response

@VoltrexKeyva VoltrexKeyva added fs Issues and PRs related to the fs subsystem / file system. linux Issues and PRs related to the Linux platform. labels Mar 11, 2024
@phyreman
Copy link

I've been getting this same error when watching a /parent directory and deleting a subdirectory that contains files.

@kylo5aby
Copy link
Contributor

I believe #51406 introduced this behavior, the FSWatch emit callback try to acquire the stat of the deleted file

const currentStats = statSync(file);

can you take a look? @mcollina

mcollina added a commit to mcollina/node that referenced this issue Apr 3, 2024
Signed-off-by: Matteo Collina <hello@matteocollina.com>
Fixes: nodejs#52018
@mcollina
Copy link
Member

mcollina commented Apr 3, 2024

Here is the fix #52349

@MoLow MoLow linked a pull request Apr 18, 2024 that will close this issue
@joscarras
Copy link

I have just being hit with this bug as well for node 20. Was the fix merged? And if not, what version will this fix be included?

nodejs-github-bot pushed a commit that referenced this issue Apr 19, 2024
Signed-off-by: Matteo Collina <hello@matteocollina.com>
Fixes: #52018
PR-URL: #52349
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
aduh95 pushed a commit that referenced this issue Apr 29, 2024
Signed-off-by: Matteo Collina <hello@matteocollina.com>
Fixes: #52018
PR-URL: #52349
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
@domosapien
Copy link

@mcollina this is also a bug in v20.12, will this be backported to that or just for v22+?

@mcollina
Copy link
Member

it should be backported

@mcollina mcollina added the lts-watch-v20.x PRs that may need to be released in v20.x label Apr 30, 2024
marco-ippolito pushed a commit that referenced this issue May 2, 2024
Signed-off-by: Matteo Collina <hello@matteocollina.com>
Fixes: #52018
PR-URL: #52349
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
marco-ippolito pushed a commit that referenced this issue May 3, 2024
Signed-off-by: Matteo Collina <hello@matteocollina.com>
Fixes: #52018
PR-URL: #52349
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system. linux Issues and PRs related to the Linux platform. lts-watch-v20.x PRs that may need to be released in v20.x
Projects
None yet
7 participants