Description
Right now Isolate.spawn()
is implemented by calling out to the embedder, which supplies a Dart_IsolateCreateCallback during Dart_Initialize
.
The VM has currently the assumption that isolates spawned via Isolate.spawn()
have the exact same source code and the same representation of source code (e.g. snapshot, ...) because message sending internally relies on the isolates to have the same class id numbering.
Unfortunately this is not safe because:
- There is no guarantee that the embedder does load the same sources in the same representation inside the
create
callback. - Even if the embedder manages to guarantee that via some mechanism, it still is flawed if we perform hot reload of one isolate (since this is not done for all isolates transitively spawned by the main isolate)
Is there a need for the embedder to implement Isolate.spawn()
- why can't the VM do that internally (by re-using the same kernel/jit/aot snapshot used for the original isolate)?
If the only reason is to enable the embedder to disallow isolate spawning we could have a callback to the embedder for asking permission to spawn but the implementation for spawning can be inside the VM.
@rmacnak-google Do you see any reason why we could not change this?
Related issues where users have already ran into this:
- "JSON-RPC error 105: Isolate must be runnable" during hot reload causes tool to crash flutter/flutter#26568
- Flutter app spawns with two isolates, hot reload fails with Error 105: Isolate must be runnable flutter/flutter#26953
- Hot reloaded changes are not applied to new isolates as they are launched flutter/flutter#18600
- Hot Reload does not update background isolate flutter/flutter#20743
- Flutter crashes when opening a compute / isolate on iOS flutter/flutter#72195