You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
Watch directory foo.
Create directory foo/bar.
Create file foo/bar/baz.txt.
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.
Modify file foo/bar/baz.txt.
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.
The text was updated successfully, but these errors were encountered:
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:foo
.foo/bar
.foo/bar/baz.txt
.DirectoryWatcher
handles theENTRY_CREATE
event forfoo/bar
, which does not notify our listener, since it only notifies on new regular files. We start listening on that directory. We missed theENTRY_CREATE
event forfoo/bar/baz.txt
since we weren't listening on thefoo/bar
directory yet at the time it was created.foo/bar/baz.txt
.DirectoryWatcher
handles theENTRY_MODIFY
event forfoo/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 subsequentENTRY_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 theENTRY_CREATE
events if the files aren't hashed yet.The text was updated successfully, but these errors were encountered: