-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fs: do not crash if the watched file is removed while setting up watch
Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: #53452 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
- Loading branch information
1 parent
76fd0ea
commit 621e073
Showing
2 changed files
with
45 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
33 changes: 33 additions & 0 deletions
33
test/parallel/test-fs-watch-recursive-linux-parallel-remove.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
|
||
if (!common.isLinux) | ||
common.skip('This test can run only on Linux'); | ||
|
||
// Test that the watcher do not crash if the file "disappears" while | ||
// watch is being set up. | ||
|
||
const path = require('node:path'); | ||
const fs = require('node:fs'); | ||
const { spawn } = require('node:child_process'); | ||
|
||
const tmpdir = require('../common/tmpdir'); | ||
const testDir = tmpdir.path; | ||
tmpdir.refresh(); | ||
|
||
const watcher = fs.watch(testDir, { recursive: true }); | ||
watcher.on('change', function(event, filename) { | ||
// This console.log makes the error happen | ||
// do not remove | ||
console.log(filename, event); | ||
}); | ||
|
||
const testFile = path.join(testDir, 'a'); | ||
const child = spawn(process.argv[0], ['-e', `const fs = require('node:fs'); for (let i = 0; i < 10000; i++) { const fd = fs.openSync('${testFile}', 'w'); fs.writeSync(fd, Buffer.from('hello')); fs.rmSync('${testFile}') }`], { | ||
stdio: 'inherit' | ||
}); | ||
|
||
child.on('exit', function() { | ||
watcher.close(); | ||
}); |