Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

fs.watchFile does not detect deletion of unmodified files under certain conditions. #4027

Closed
dominictarr opened this issue Sep 15, 2012 · 4 comments
Labels

Comments

@dominictarr
Copy link

If you fs.watchFile(file,...) a newly created flie in the listener of a fs.watchFile on it's parent directory,
then delete that file without otherwise modifying it, then that delete will never be noticed.

Here is a script to reproduce:
https://gist.github.com/50ac9170e4615df2b644

first discovered this here
mikeal/watch#36

This bug only strikes when you start watching a new file in response to it's creation (which you detected by watching it's directory). If the file already exists when you start node, (and you start watching it after traversing that directory) then it will be detected correctly.

the deletion can be detected by doing an fs.readdir,
and then comparing that list to what you though you had.
but there is probably a much better way to fix this bug.

@bnoordhuis
Copy link
Member

Can you post the expected and actual output that you're seeing? I'm under the impression that it WFM. Here is what I see:

> rm hello
> touch hello2
modify /home/bnoordhuis/src/nodejs/master/hello2 Sun Sep 16 2012 01:23:14 GMT+0200 (CEST)
> rm hello2
delete /home/bnoordhuis/src/nodejs/master/hello2 Thu Jan 01 1970 01:00:00 GMT+0100 (CET)

Also, on what OS is this?

@dominictarr
Copy link
Author

oh sorry. I didn't describe the script correctly.

There are two files in the script, hello, and hello2.
hello sees

touch hello
rm hello

and hello2 gets

touch hello2
touch hello2
rm hello2

(both with pauses to allow fs.watchFile time)

The problem is rm hello is not detected.
hello2 is touched twice, and that is what works around the bug.

So, I'm expecting:

rm hello
delete /home/bnoordhuis/src/nodejs/master/hello Sun Sep 16 2012 01:23:14 GMT+0200 (CEST)

But that doesn't happen.

I'm on ubuntu 12

@bnoordhuis
Copy link
Member

Thanks, confirmed. Fixed in 39a0836.

@dominictarr
Copy link
Author

sweet! thanks!

jBarz pushed a commit to ibmruntimes/node that referenced this issue Sep 6, 2017
The sequential/test-regress-GH-4027 test is flaky with an increased
system load, failing when the watched file is unlinked before the
first state of the watched file is retrieved.

After increasing the delay before unlinking and calling setTimeout
after watchFile, the flakiness stopped reproducing.

PR-URL: nodejs/node#14010
Fixes: nodejs/node#13800
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants