Skip to content

Commit b8daa53

Browse files
DanTupCommit Queue
authored andcommitted
[analysis_server] Don't rebuild contexts on deletion of an analysis root
This is a partial revert of ca95230 (it removes the behaviour change and the test that verifies this, but leaves two additional tests that were added relating to roots that are created later). If we rebuild contexts when a root is deleted, we may get stuck in a loop because we will again try to recreate the same (deleted) root, and then the watcher will close in a way that looks like a deleted folder, and we will repeat. Fixes #60863 Change-Id: I10289160b341d273e8e409184a1c013c7fb9439d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433140 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 26e9c82 commit b8daa53

File tree

2 files changed

+10
-57
lines changed

2 files changed

+10
-57
lines changed

pkg/analysis_server/lib/src/context_manager.dart

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ class ContextManagerImpl implements ContextManager {
227227
HashMap<Folder, AnalysisDriver>();
228228

229229
/// Subscriptions to watch included resources for changes.
230-
final Set<StreamSubscription<WatchEvent>> watcherSubscriptions = {};
230+
final List<StreamSubscription<WatchEvent>> watcherSubscriptions = [];
231231

232232
/// Whether or not the watchers have been paused.
233233
///
@@ -623,24 +623,12 @@ class ContextManagerImpl implements ContextManager {
623623
for (var included in analysisContext.contextRoot.included) {
624624
var watcher = included.watch();
625625
watchers.add(watcher);
626-
var watcherSubscription = watcher.changes.listen(
627-
_scheduleWatchEvent,
628-
onError: _handleWatchInterruption,
626+
watcherSubscriptions.add(
627+
watcher.changes.listen(
628+
_scheduleWatchEvent,
629+
onError: _handleWatchInterruption,
630+
),
629631
);
630-
watcherSubscriptions.add(watcherSubscription);
631-
// When a directory is deleted, the watcher will be closed. Detect
632-
// this by checking whether the watcher is still active in
633-
// `changeSubscriptions` (it will first be removed if we are
634-
// closing the watcher ourselves).
635-
watcherSubscription.onDone(() {
636-
if (watcherSubscriptions.contains(watcherSubscription)) {
637-
_instrumentationService.logInfo(
638-
'Watcher for $rootFolder unexpectedly closed. '
639-
'Assuming root was deleted, rebuilding...',
640-
);
641-
refresh();
642-
}
643-
});
644632
}
645633

646634
_watchBlazeFilesIfNeeded(rootFolder, driver);
@@ -778,14 +766,10 @@ class ContextManagerImpl implements ContextManager {
778766
}
779767

780768
Future<void> _destroyAnalysisContexts() async {
781-
// Clear `watcherSubscriptions` before cancelling each subscription
782-
// because the presences of a watcher in `watcherSubscriptions` is used
783-
// to know if the watcher closed prematurely.
784-
var subscriptionsToCancel = watcherSubscriptions.toSet();
769+
for (var subscription in watcherSubscriptions) {
770+
await subscription.cancel();
771+
}
785772
watcherSubscriptions.clear();
786-
await Future.wait(
787-
subscriptionsToCancel.map((subscription) => subscription.cancel()),
788-
);
789773

790774
var collection = _collection;
791775
_collection = null;

pkg/analysis_server/test/integration/analysis/error_test.dart

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,7 @@ void main() {
1818
@reflectiveTest
1919
class AnalysisErrorIntegrationTest
2020
extends AbstractAnalysisServerIntegrationTest {
21-
Future<void> test_analysisRootDeleted_rebuildsContexts() async {
22-
// To simplify testing, use two analysis roots. When we delete one of them
23-
// we can use the notification of diagnostics sent for the other as
24-
// validation that contexts were rebuilt.
25-
var rootToKeepPath = sourcePath('packageKeep');
26-
var filetoKeepPath = sourcePath('packageKeep/lib/test.dart');
27-
var rootToDeletePath = sourcePath('packageDelete');
28-
var fileToDeletePath = sourcePath('packageDelete/lib/test.dart');
29-
var content = 'invalidCode';
30-
31-
// Create the folders/files up-front.
32-
writeFile(filetoKeepPath, content);
33-
writeFile(fileToDeletePath, content);
34-
35-
await sendServerSetSubscriptions([ServerService.STATUS]);
36-
await sendAnalysisSetAnalysisRoots([rootToKeepPath, rootToDeletePath], []);
37-
await analysisFinished;
38-
39-
// Start listening for the kept root being re-analyzed as a signal that
40-
// the rebuild has completed.
41-
var keptFileDiagnostics = onAnalysisErrors.firstWhere(
42-
(params) => params.file == filetoKeepPath,
43-
);
44-
45-
// Delete the folder which should trigger a rebuild.
46-
deleteFolder(rootToDeletePath);
47-
48-
// Ensure this completes.
49-
await keptFileDiagnostics;
50-
}
51-
52-
Future<void> test_analysisRootDoesNotExist_addOverlay() async {
21+
Future<void> test_analysisRootDoesNotExist() async {
5322
var packagePath = sourcePath('package');
5423
var filePath = sourcePath('package/lib/test.dart');
5524
var content = '''

0 commit comments

Comments
 (0)