Skip to content

How to make Isolate.spawn() safe #36648

Closed
@mkustermann

Description

@mkustermann

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:

Metadata

Metadata

Assignees

Labels

area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.library-isolate

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions