Skip to content

Commit 443d724

Browse files
monakavparfonov
authored andcommitted
Process exclusive by using synchronized. (eclipse-che#6205)
Signed-off-by: Masaki Muranaka <monaka@monami-ya.com>
1 parent 800dd40 commit 443d724

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/vfs/watcher/FileWatcherService.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,11 @@ public void register(Path dir) {
191191
} else {
192192
try {
193193
LOG.debug("Starting watching directory '{}'", dir);
194-
WatchKey watchKey = dir.register(service, eventKinds, eventModifiers);
195-
keys.put(watchKey, dir);
196-
registrations.put(dir, 1);
194+
synchronized (keys) {
195+
WatchKey watchKey = dir.register(service, eventKinds, eventModifiers);
196+
keys.put(watchKey, dir);
197+
registrations.put(dir, 1);
198+
}
197199
} catch (IOException e) {
198200
LOG.error("Can't register dir {} in file watch service", dir, e);
199201
}
@@ -275,7 +277,17 @@ private void run() {
275277
while (running.get()) {
276278
try {
277279
WatchKey watchKey = service.take();
278-
Path dir = keys.get(watchKey);
280+
Path dir;
281+
synchronized (keys) {
282+
dir = keys.get(watchKey);
283+
}
284+
285+
if (dir == null) {
286+
resetAndRemove(watchKey, dir);
287+
288+
LOG.debug("Reported directory is not registered - skipping.");
289+
continue;
290+
}
279291

280292
List<WatchEvent<?>> watchEvents = watchKey.pollEvents();
281293

0 commit comments

Comments
 (0)