Skip to content

Commit 54eef34

Browse files
ntkmenex3
andauthored
Fix a race condition where isolates could be spawned after kill (#2306)
Co-authored-by: Natalie Weizenbaum <[email protected]>
1 parent 613fb17 commit 54eef34

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
* Fix an edge case where the Dart VM could hang when shutting down when requests
1515
were in flight.
1616

17+
* Fix a race condition where the embedded host could fail to shut down if it was
18+
closed around the same time a new compilation was started.
19+
1720
## 1.77.8
1821

1922
* No user-visible changes.

lib/src/embedded/isolate_dispatcher.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class IsolateDispatcher {
2727
/// All isolates that have been spawned to dispatch to.
2828
///
2929
/// Only used for cleaning up the process when the underlying channel closes.
30-
final _allIsolates = <Future<ReusableIsolate>>[];
30+
final _allIsolates = StreamController<ReusableIsolate>();
3131

3232
/// The isolates that aren't currently running compilations
3333
final _inactiveIsolates = <ReusableIsolate>{};
@@ -87,10 +87,8 @@ class IsolateDispatcher {
8787
}
8888
}, onError: (Object error, StackTrace stackTrace) {
8989
_handleError(error, stackTrace);
90-
}, onDone: () async {
91-
for (var isolate in _allIsolates) {
92-
(await isolate).kill();
93-
}
90+
}, onDone: () {
91+
_allIsolates.stream.listen((isolate) => isolate.kill());
9492
});
9593
}
9694

@@ -106,8 +104,8 @@ class IsolateDispatcher {
106104
_inactiveIsolates.remove(isolate);
107105
} else {
108106
var future = ReusableIsolate.spawn(_isolateMain);
109-
_allIsolates.add(future);
110107
isolate = await future;
108+
_allIsolates.add(isolate);
111109
}
112110

113111
_activeIsolates[compilationId] = isolate;

0 commit comments

Comments
 (0)