Open Nemo64 opened 3 years ago
I can reproduce this.
queueMicrotask
:I assume it's an internal queue that is overflowing if you don't consume the events quickly enough. If you write files sequentially, it mostly gets all events.
for (let index = 1; index <= 100; index += 1) {
await Deno.writeTextFile(`${FOLDER}/file${index}`, `content of file${index}`);
}
If you let the watcher run and use a shell script in the test
folder find . -name "file*"-print0 |xargs -0 -I {} mv {} {}_
then deno also gets about 80% of events (it looks like 2 modify and 1 create, no remove though). If you speed it up with find . -name "file*" -print0 |xargs -P8 -0 -I {} mv {} {}_
, you get fewer events (about 50%).
These numbers vary strongly based on what your machine is doing.
so interestingly somewhat related. I discovered that Deno.watchFs
cannot properly track neovim writes. I believe this comes down to the way neovim uses swap files. What's interesting is that this is a problem with the os. E.g. this is what a small test script produces:
for await (const event of Deno.watchFs('./bin/moon_phase.sh') {
console.log({event})
}
{
event: [Object: null prototype] {
kind: "modify",
paths: [ "/home/andrew/bin/moon_phase.sh" ],
flag: null
}
}
{
event: [Object: null prototype] {
kind: "modify",
paths: [ "/home/andrew/bin/moon_phase.sh" ],
flag: null
}
}
{
event: [Object: null prototype] {
kind: "remove",
paths: [ "/home/andrew/bin/moon_phase.sh" ],
flag: null
}
}
and this is what inotifywait -m ./bin/moon_phase.sh
outputs:
Setting up watches.
Watches established.
/home/andrew/bin/moon_phase.sh MOVE_SELF
/home/andrew/bin/moon_phase.sh ATTRIB
/home/andrew/bin/moon_phase.sh DELETE_SELF
in both cases I updated and saved the file multiple times but only the very first event was captured. I don't know if this belongs under its own issue, I imagine the only thing deno would do is add some magic on top of the os watcher to see if files need to be watched under a new inode or something. I wanted to start here though and see if someone tells me this is issue worthy. I probably could solve this myself by reinstantiating the Deno.watchFs
every time I see a remove
event
@andykais I don't know if you're still fighting this, but it appears you're losing the watch because the file you're watching is being deleted. Vim editors save in interesting ways, see here for good rundown and in particular how it affects watchers:
https://brandur.org/live-reload#vim
I don't think this is a Deno thing. I know about the vim quirks because I ran into similar issues in a Go program.
I wrote this little test script:
It creates a
test
directory and watches it for changes. Then, it creates 100 files in it.What I would expect is 100 or 200 events (100 create and 100 modify). What I instead get is this:
Just 19 events.
To verify that this is not an os issue, I ran the test with
inotifywatch test
which outputs this result:So basically the expected number of events.
On macOs, I used
fswatch -r test
and then copied the result intopbpaste|wc -l
which showed 100 events, so nothing was lost on the os level either.I ran this test on
Linux 5.4.0-72-generic #80-Ubuntu SMP Mon Apr 12 17:35:00 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
Darwin [hostname] 20.5.0 Darwin Kernel Version 20.5.0: Sat May 8 05:10:33 PDT 2021; root:xnu-7195.121.3~9/RELEASE_X86_64 x86_64
EDIT: with the currently newest stable deno version