Repository navigation
Conversation
PollingWatchService cancelled the key when the directory could no longer be snapshotted (for example after it was deleted), but never queued it, so a thread blocked in WatchService.take() was never woken up and could not find out that the key was invalid. Signal the key after cancelling it, as the JDK's own polling and Linux watch services do. Fixes google#72
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #72.
When a directory registered with a Jimfs
WatchServiceis deleted, the polling task fails to snapshot it and cancels the key, but it never queues the key. A thread blocked intake()therefore keeps waiting forever and never learns that the key became invalid.The JDK services handle this case by cancelling and then signalling the key (
sun.nio.fs.PollingWatchServicedoescancel(); signal();when the directory is no longer accessible, andLinuxWatchServicedoes the same onIN_IGNORED). On the default file system on Linux,poll()returns the key after the directory is deleted, withisValid() == falseandreset() == false.This change makes Jimfs do the same thing by calling
key.signal()right afterkey.cancel()in the polling task'sIOExceptionbranch.close()still cancels keys without queueing them, so its behavior is unchanged.Testing:
PollingWatchServiceTest.testDeletingWatchedDirectoryCancelsAndSignalsKey. It registers a directory, deletes it, and expectspoll(1, SECONDS)to return the same key, now invalid.expected specific instance: ...Key@... but was: null.PollingWatchServiceTestpasses 9/9.jimfsmodule:mvn testpasses 5906 tests (1 skipped), JDK 21.