Skip to content

Commit

Permalink
[io/file_watch] Don't attempt to close already closed DirectoryWatchH…
Browse files Browse the repository at this point in the history
…andle.

Fixes #43941

TEST=Running four dart scripts in parallel that delete/watch thousands of file reproduces the failure after several minutes. After the fix it no longer reproduces.

Change-Id: I6a0a928838c676f44e747a822611b56f0ffc4841
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169601
Reviewed-by: Siva Annamalai <[email protected]>
Commit-Queue: Alexander Aprelev <[email protected]>
  • Loading branch information
aam authored and [email protected] committed Oct 31, 2020
1 parent 77f2019 commit da133e5
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions sdk/lib/_internal/vm/bin/file_patch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,17 @@ abstract class _FileSystemWatcher {
assert(watcherPath.count > 0);
watcherPath.count--;
if (watcherPath.count == 0) {
_unwatchPath(_id!, watcherPath.pathId);
_pathWatchedEnd();
_idMap.remove(watcherPath.pathId);
var pathId = watcherPath.pathId;
// DirectoryWatchHandle(aka pathId) might be closed already initiated
// by issueReadEvent for example. When that happens, appropriate closeEvent
// will arrive to us and we will remove this pathId from _idMap. If that
// happens we should not try to close it again as pathId is no
// longer usable(the memory it points to might be released)
if (_idMap.containsKey(pathId)) {
_unwatchPath(_id!, pathId);
_pathWatchedEnd();
_idMap.remove(pathId);
}
}
_watcherPath = null;
}
Expand Down

0 comments on commit da133e5

Please sign in to comment.