Skip to content

Commit c58d263

Browse files
[analysis_server] Handle directory watcher closed on windows.
Change-Id: I11d1d9a324ebb27a920837ee4382b89e7cbb0253 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/125765 Reviewed-by: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Mike Fairhurst <[email protected]>
1 parent a87c563 commit c58d263

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

pkg/analysis_server/lib/src/context_manager.dart

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,8 +786,8 @@ class ContextManagerImpl implements ContextManager {
786786
bool isManaged = rootInfo._managesOrHasChildThatManages(includedPath);
787787
if (!isManaged) {
788788
ContextInfo parent = _getParentForNewContext(includedPath);
789-
changeSubscriptions[includedFolder] =
790-
includedFolder.changes.listen(_handleWatchEvent);
789+
changeSubscriptions[includedFolder] = includedFolder.changes
790+
.listen(_handleWatchEvent, onError: _handleWatchInterruption);
791791
_createContexts(parent, includedFolder, excludedPaths, false);
792792
}
793793
}
@@ -1407,6 +1407,15 @@ class ContextManagerImpl implements ContextManager {
14071407
callbacks.afterWatchEvent(event);
14081408
}
14091409

1410+
/// On windows, the directory watcher may overflow, and we must recover.
1411+
void _handleWatchInterruption(dynamic error, StackTrace stackTrace) {
1412+
// We've handled the error, so we only have to log it.
1413+
AnalysisEngine.instance.instrumentationService
1414+
.logError('Watcher error; refreshing contexts.\n$error\n$stackTrace');
1415+
// TODO(mfairhurst): Optimize this, or perhaps be less complete.
1416+
refresh(null);
1417+
}
1418+
14101419
void _handleWatchEventImpl(WatchEvent event) {
14111420
// Figure out which context this event applies to.
14121421
// TODO(brianwilkerson) If a file is explicitly included in one context

pkg/analyzer/lib/file_system/physical_file_system.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,12 @@ class _PhysicalFolder extends _PhysicalResource implements Folder {
262262
@override
263263
Stream<WatchEvent> get changes =>
264264
new DirectoryWatcher(_entry.path).events.handleError((error) {},
265-
test: (error) => error is io.FileSystemException);
265+
test: (error) =>
266+
error is io.FileSystemException &&
267+
// Don't suppress "Directory watcher closed," so the outer
268+
// listener can see the interruption & act on it.
269+
!error.message
270+
.startsWith("Directory watcher closed unexpectedly"));
266271

267272
/**
268273
* Return the underlying file being represented by this wrapper.

0 commit comments

Comments
 (0)