Skip to content

Signal the watch key when its watched directory goes away. - #525

Merged
copybara-service[bot] merged 1 commit into
masterfrom
test_994360781
Oct 6, 2026
Merged

copybara-service[bot] merged 1 commit into
masterfrom
test_994360781

Conversation

@copybara-service

Copy link
Copy Markdown
Contributor

Signal the watch key when its watched directory goes away.

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.

Compare the JDK's test for this scenario.

Fixes #72

Fixes #524

RELNOTES=n/a

`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.

Compare [the JDK's test for this scenario](https://github.com/openjdk/jdk/blob/4691e9c192cc30c4c08d46632f248c463b3bd48c/test/jdk/java/nio/file/WatchService/Basic.java#L199).

Fixes #72

Fixes #524

RELNOTES=n/a
PiperOrigin-RevId: 994601353
@copybara-service
copybara-service Bot merged commit b014510 into master Oct 6, 2026
@copybara-service
copybara-service Bot deleted the test_994360781 branch October 6, 2026 20:45
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.

WatchService registered directory gets deleted, but nothing happens.

1 participant