Skip to content
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

Fix for a race condition on Linux #1228

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

dividedmind
Copy link

Sometimes, when another process just happened to create a file
when we were setting up a watch, the new file wouldn't be noticed.

To prevent the event not being generated in this case, schedule
a directory rescan immediately after setting up a watch.

Fixes #1112


Also, another commit here to fix brittle tests. It might be related to #923

In two of the tests there were unlink() calls at the end of an
asynchronously executed function. These calls would sometimes end
up executing only after the test has finished and after cleanup,
leading to them erroring out due to target files no longer around.

These failures would cause exceptions reported in other, unrelated
tests. Since the tests containing them work just fine without the
unlink calls (as is evident by the fact that tests passed even if
they executed after finishing the case) simply removing them fixes
the problem and makes the test suite reliable.
@paulmillr
Copy link
Owner

good stuff!

@dividedmind
Copy link
Author

Looks like the fix is breaking some tests on non-linux platforms. Do you think it's a good idea to conditionally do this on Linux only? Or do you think the failures are unrelated? I don't have access to either platform so I can't say for sure, but the test suite is quite brittle. The one fix I included here seemed to be enough to get it to pass robustly on my system, but there might be more dragons there.

@paulmillr
Copy link
Owner

The nodefs-handler is not used on macos, so i'm not sure how to fix it. Maybe in the same way in fsevents-handler.

@dividedmind
Copy link
Author

That's a good point, I forgot. In this case I think it's fair to say that these test failures must be unrelated.

Sometimes, when another process just happened to create a file
when we were setting up a watch, the new file wouldn't be noticed.

To prevent the event not being generated in this case, schedule
a directory rescan immediately after setting up a watch.

Fixes paulmillr#1112
@dividedmind dividedmind force-pushed the fix/new-file-new-directory-race-on-linux branch from a2ea88c to 95bc9cd Compare July 10, 2022 18:08
@dividedmind
Copy link
Author

I changed it to only do the readdir if polling is enabled and added a workaround for a Node 8 bug. I wanted to take a look at more Node 8 test problems, but then I realized it's over two years past EOL and it's probably not worth the trouble. I verified tests pass robustly on Node >= 14 on Linux. The MacOS and Windows test failures seem unrelated, so I think this is good to merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Race condition when watching dirs leads to missed files
2 participants