Skip to content

Commit

Permalink
Fix duplicated isolates for the same compilation id (#2308)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntkme committed Aug 16, 2024
1 parent aaadd3f commit 386445b
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/src/embedded/isolate_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class IsolateDispatcher {
final _inactiveIsolates = <ReusableIsolate>{};

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

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

if (compilationId != 0) {
var isolate = _activeIsolates[compilationId] ??
await _getIsolate(compilationId);
var isolate = await _activeIsolates.putIfAbsent(
compilationId, () => _getIsolate(compilationId!));
try {
isolate.send(packet);
return;
Expand Down Expand Up @@ -108,7 +108,6 @@ class IsolateDispatcher {
_allIsolates.add(isolate);
}

_activeIsolates[compilationId] = isolate;
isolate.checkOut().listen(_channel.sink.add,
onError: (Object error, StackTrace stackTrace) {
if (error is ProtocolError) {
Expand Down

0 comments on commit 386445b

Please sign in to comment.