Skip to content

Commit

Permalink
Fix a race condition where isolates could be spawned after kill (#2306)
Browse files Browse the repository at this point in the history
Co-authored-by: Natalie Weizenbaum <nweiz@google.com>
  • Loading branch information
ntkme and nex3 committed Aug 12, 2024
1 parent 613fb17 commit 54eef34
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
* Fix an edge case where the Dart VM could hang when shutting down when requests
were in flight.

* Fix a race condition where the embedded host could fail to shut down if it was
closed around the same time a new compilation was started.

## 1.77.8

* No user-visible changes.
Expand Down
10 changes: 4 additions & 6 deletions lib/src/embedded/isolate_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class IsolateDispatcher {
/// All isolates that have been spawned to dispatch to.
///
/// Only used for cleaning up the process when the underlying channel closes.
final _allIsolates = <Future<ReusableIsolate>>[];
final _allIsolates = StreamController<ReusableIsolate>();

/// The isolates that aren't currently running compilations
final _inactiveIsolates = <ReusableIsolate>{};
Expand Down Expand Up @@ -87,10 +87,8 @@ class IsolateDispatcher {
}
}, onError: (Object error, StackTrace stackTrace) {
_handleError(error, stackTrace);
}, onDone: () async {
for (var isolate in _allIsolates) {
(await isolate).kill();
}
}, onDone: () {
_allIsolates.stream.listen((isolate) => isolate.kill());
});
}

Expand All @@ -106,8 +104,8 @@ class IsolateDispatcher {
_inactiveIsolates.remove(isolate);
} else {
var future = ReusableIsolate.spawn(_isolateMain);
_allIsolates.add(future);
isolate = await future;
_allIsolates.add(isolate);
}

_activeIsolates[compilationId] = isolate;
Expand Down

0 comments on commit 54eef34

Please sign in to comment.