This PR fixes a bug where multiple isolates may be spawned for the same compilation id due to async gap between checking _activeIsolates[compilationId] and assigning _activeIsolates[compilationId] = isolate;, if the host sends packets with the same compilation id extremely quickly.
Current buggy behavior:
Packet A (compilationId: 1): _activeIsolates[compilationId] is null, spawning new isolate asynchronously.
Packet B (compilationId: 1): _activeIsolates[compilationId] is null, spawning new isolate asynchronously.
Packet A (compilationId: 1): new isolate spawned, _activeIsolates[compilationId] = isolate;.
Packet B (compilationId: 1): new isolate spawned, _activeIsolates[compilationId] = isolate;.
Fixed:
Packet A (compilationId: 1): _activeIsolates[compilationId] is null, _activeIsolates[compilationId] = future;, spawning new isolate asynchronously.
Packet B (compilationId: 1): _activeIsolates[compilationId] is not null, return future.
Packet A (compilationId: 1): new isolate spawned, future resolved.
Packet B (compilationId: 1): future resolved, throw Received multiple messages for compilation ID $compilationId.
This PR fixes a bug where multiple isolates may be spawned for the same compilation id due to async gap between checking
_activeIsolates[compilationId]
and assigning_activeIsolates[compilationId] = isolate;
, if the host sends packets with the same compilation id extremely quickly.Current buggy behavior:
_activeIsolates[compilationId] is null
, spawning new isolate asynchronously._activeIsolates[compilationId] is null
, spawning new isolate asynchronously._activeIsolates[compilationId] = isolate;
._activeIsolates[compilationId] = isolate;
.Fixed:
_activeIsolates[compilationId] is null
,_activeIsolates[compilationId] = future;
, spawning new isolate asynchronously._activeIsolates[compilationId] is not null
, returnfuture
.future
resolved.future
resolved, throwReceived multiple messages for compilation ID $compilationId
.