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

Race conditions on new directory creation #11

Open
gmethvin opened this issue Sep 27, 2017 · 0 comments
Open

Race conditions on new directory creation #11

gmethvin opened this issue Sep 27, 2017 · 0 comments

Comments

@gmethvin
Copy link

gmethvin commented Sep 27, 2017

I've been adapting this code for use in Play Framework and ran into an interesting race condition with the JDK DirectoryWatcher implementation. Consider the following scenario:

  1. Watch directory foo.
  2. Create directory foo/bar.
  3. Create file foo/bar/baz.txt.
  4. DirectoryWatcher handles the ENTRY_CREATE event for foo/bar, which does not notify our listener, since it only notifies on new regular files. We start listening on that directory. We missed the ENTRY_CREATE event for foo/bar/baz.txt since we weren't listening on the foo/bar directory yet at the time it was created.
  5. Modify file foo/bar/baz.txt.
  6. DirectoryWatcher handles the ENTRY_MODIFY event for foo/bar/baz.txt, but because we did not get the original create event and there is no existing hash, no change notification is sent.

The biggest problem here is that we miss the ENTRY_CREATE events for some new files, which triggers us to ignore the subsequent ENTRY_MODIFY events. I'm also not clear on why we don't send a change notification when a directory is created. I think we should either notify on new directories and leave it up to the user of the API to decide what to do with the initial state of the directory, or explicitly generate the ENTRY_CREATE events if the files aren't hashed yet.

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

No branches or pull requests

1 participant