Skip to content

Commit da133e5

Browse files
aamcommit-bot@chromium.org
authored andcommitted
[io/file_watch] Don't attempt to close already closed DirectoryWatchHandle.
Fixes dart-lang/sdk#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 <asiva@google.com> Commit-Queue: Alexander Aprelev <aam@google.com>
1 parent 77f2019 commit da133e5

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

sdk/lib/_internal/vm/bin/file_patch.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,17 @@ abstract class _FileSystemWatcher {
174174
assert(watcherPath.count > 0);
175175
watcherPath.count--;
176176
if (watcherPath.count == 0) {
177-
_unwatchPath(_id!, watcherPath.pathId);
178-
_pathWatchedEnd();
179-
_idMap.remove(watcherPath.pathId);
177+
var pathId = watcherPath.pathId;
178+
// DirectoryWatchHandle(aka pathId) might be closed already initiated
179+
// by issueReadEvent for example. When that happens, appropriate closeEvent
180+
// will arrive to us and we will remove this pathId from _idMap. If that
181+
// happens we should not try to close it again as pathId is no
182+
// longer usable(the memory it points to might be released)
183+
if (_idMap.containsKey(pathId)) {
184+
_unwatchPath(_id!, pathId);
185+
_pathWatchedEnd();
186+
_idMap.remove(pathId);
187+
}
180188
}
181189
_watcherPath = null;
182190
}

0 commit comments

Comments
 (0)