Skip to content

Commit 386445b

Browse files
authored
Fix duplicated isolates for the same compilation id (#2308)
1 parent aaadd3f commit 386445b

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

lib/src/embedded/isolate_dispatcher.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class IsolateDispatcher {
3333
final _inactiveIsolates = <ReusableIsolate>{};
3434

3535
/// A map from active compilationIds to isolates running those compilations.
36-
final _activeIsolates = <int, ReusableIsolate>{};
36+
final _activeIsolates = <int, Future<ReusableIsolate>>{};
3737

3838
/// A pool controlling how many isolates (and thus concurrent compilations)
3939
/// may be live at once.
@@ -54,8 +54,8 @@ class IsolateDispatcher {
5454
(compilationId, messageBuffer) = parsePacket(packet);
5555

5656
if (compilationId != 0) {
57-
var isolate = _activeIsolates[compilationId] ??
58-
await _getIsolate(compilationId);
57+
var isolate = await _activeIsolates.putIfAbsent(
58+
compilationId, () => _getIsolate(compilationId!));
5959
try {
6060
isolate.send(packet);
6161
return;
@@ -108,7 +108,6 @@ class IsolateDispatcher {
108108
_allIsolates.add(isolate);
109109
}
110110

111-
_activeIsolates[compilationId] = isolate;
112111
isolate.checkOut().listen(_channel.sink.add,
113112
onError: (Object error, StackTrace stackTrace) {
114113
if (error is ProtocolError) {

0 commit comments

Comments
 (0)