Recursive fs.watch crashes on Linux when deleting files #52018
Closed
Description
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