-
Notifications
You must be signed in to change notification settings - Fork 113
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
Mkdir -p are not correctly reported on Linux #60
Comments
That's pretty interesting. So it's difficult to say if there is a good solution to this problem. I think you already have the right impression, but it's like the directory foo gets created, and before NSFW even has time to react to create the inotify watch on foo, I imagine that bar and baz are also created. After the mkdir -p completes, do file events get reported from bar and baz? |
Yes, events are reported from bar and baz after that. For example, if I create a
|
So while it doesn't report the creation of bar and baz, is that necessarily important? I imagine as a package that utilizes NSFW, when I get the event for foo's creation I will probably scan that directory and do whatever I'm supposed to do at that time. Getting the individual reports on the way to baz is probably less important overall. Is that reasonable to expect? |
Well, often, it is not the directories but the files that are interesting. And it can happen with files too. For example: $ mkdir -p foo/bar
$ echo baz > foo/bar/baz
$ mv foo /path/to/watched/dir/ will report only an event for The first example I can think of is if the added directory contains two sub-directories, one with a lot of things inside and the other is just empty. If NSFW starts with the big sub-directory and the user scan starts the empty directory, the inotify watch can be setup after the scan, and during the time, it a file is created in this empty directory, it will be missed. It's an edge case, but it looks like these edge cases happen more often that I'd like when I'm working with file system watchers. So, in my humble opinion, it would be better if NSFW emits the events in this case. But I also understand that you may want to do that as it increases what NSFW does, and it has a cost to maintain this code. Maybe a middleground can be to add documentation for the edge cases like this. |
We have been troubled by the same bug. How do you work around in the end? |
We have another use case. We watch the creation of files with specific extensions. Once those files are created as part of yeoman generator together with their parent folder, most of the times those file creation events are missing. |
To me it seems that the right thing to do would be this, whenever a directory "created" event is detected:
my assumption is that after creating the watch in step 2, we would get an inotify event for any entry created after that line. So iterating the directory afterwards, we would be sure to catch all entries created before that line. We might get a couple of entries created later, but that is not relevant, since we check whether we've seen the entry in line 1. WDYT? |
@marechal-p any thoughts? |
@tsmaeder emitting virtual events while iterating over the file tree seems good to me. I've been trying to reproduce on Windows to see if that too would need a fix but I am having issues running nsfw at all, I don't get any events for some reason... |
@marechal-p it's a linux-specific problem. Windows & Mac file watcher API's are much saner that Linux. |
I looked some more into this issue, and there is in fact a "blind spot" where NSFW will just completely miss some folders. I was able to reproduce it on the following branch: master...theia-ide:mp/linux-tree-race In the reproduction commit I modified the C++ sources to create a folder in what I believe is the blind spot, but that folder could in fact be created by any other process. I added a test that checks that events for other folders are correctly emitted, and that this extra folder created during the blind spot is never handled. So there are two problems:
|
TL;DR: any process that quickly creates folders on the fs will participate in a race with NSFW trying to keep up, and with lucky timing a folder can be created in NSFW's blind spot and never be handled. From the top of my head, programs like |
I think my solution would still close that window of vulnerability. |
@tsmaeder are you working on an implementation for it? |
No time for fun stuff currently 🤷. |
Description
When creating recursively directories with
mkdir -p
, the watcher only reports the first directory.Steps to Reproduce
nsfw /tmp
mkdir -p /tmp/foo/bar/baz
Expected behavior:
The watcher says that directories
foo
,foo/bar
andfoo/bar/baz
have been created:Actual behavior:
The watcher only says that the directory
foo
has been created:Additional Information
As far as I know, inotify is not recursive, and it's
nsfw
code that creates sub-watchers for directories inside the watched directory. When inotify sends the event forfoo
, the directoriesfoo/bar
andfoo/bar/baz
have already been created, so even if the watcher is able to find these directories to tell inotify to watch them, it fails to also send an event for them.The text was updated successfully, but these errors were encountered: