-
Notifications
You must be signed in to change notification settings - Fork 112
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
linux: fix missing events #127
Conversation
@implausible heads up. This is something we wanted to fix for Theia, but it should affect GitKraken as well? |
47a0ea4
to
5e08354
Compare
Signed-off-by: Paul Maréchal <paul.marechal@ericsson.com>
There is a window where some created folders might get ignored completely. It happens between the time where the tree is created and the time where the tree is iterated over to allocate watchers. This commit hoist the inotify watching before doing scandir. This way there is no window where a directory might be created after the initial scandir and missed, as the inotify watcher should pick it up. Signed-off-by: Paul Maréchal <paul.marechal@ericsson.com>
5e08354
to
79a1943
Compare
I added a |
This is awesome. Quick look, I'm a bit concerned that the testing apparatus is strongly tied to the implementation details of the libraries codebase. I will come back with a suggestion hopefully this week. |
I mean... leveraging conditional compilation to set the test mechanism might be better? I wonder if we set an environment variable if we could pick it up as a define in gyp land. Then only in the test run does this codepath exist. |
Good idea, I'll do that! |
6eadcd9
to
1ee52c2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@implausible I implemented the build-time macro like suggested.
fb78f4c
to
ef061c9
Compare
I exposed the Napi NSFW object through |
ef061c9
to
59b7f66
Compare
CI is getting stuck on some test but I can't reproduce on my Linux machine. Can someone else confirm? |
7094910
to
94163de
Compare
Added a |
94163de
to
f029e51
Compare
That's usually a sign that the native module did not cleanly shutdown, and is usually bar to investigate and fix. Here are the things that can cause the test suite not to exit:
|
js/spec/nested-file-test.js
Outdated
await fse.mkdirp(directory); | ||
await fse.close(await fse.open(filePath, 'w')); | ||
await Promise.race([ | ||
sleep(folders.length * 500 * 1.5), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the timer that's holding on for dear life? Maybe we should cancel the timeout if it loses the race.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked with why-is-node-running
after the test and the event loop was empty. Also that sleep is not going on for an hour, which is the time it took for CI to be cancelled... Lastly is it possible to cancel promisified timeouts? I didn't bother for the aforementioned reasons.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And what confuses even more is that on two different Linux machines the test runs fine, the issue only happens with GitHub Actions for some reason...
Most clients expect every new file from a new tree being added in the watched directory to be reported. This is currently not the case if the tree appears too quickly on disk. This commit propagates a callback down the recursive tree building to make sure that all files added are being reported as created to clients. I also added an environment variable check for use when testing: `NSFW_TEST_SLOW`. When set to `1` nsfw will artificially sleep before crawling folders on the fs. This is to simulate the case when nsfw is late to the party and sub-folders were created before we had time to allocate inotify watchers. In such a case, we need to manually emit CREATED events for new files and folders discovered by scandir. Signed-off-by: Paul Maréchal <paul.marechal@ericsson.com>
f029e51
to
f34d5b1
Compare
@implausible I inlined the test and added the |
Thanks 😄 |
See individual commit messages for more details.
NSFW's linux implementation suffers from a small window of opportunity where if a folder is created, it will go totally undetected. See #60 (comment). The first commit addresses that issue by allocating the inotify watcher before doing scandir when recursively building the node tree.
The second commit tries to emit creation events for nested files and folders of newly added sub-trees. It was a bit up to luck before if NSFW would report something from inside that nested tree, but now it should always properly dive inside and report all files.
Fixes #60