Skip to content

Isolate.spawn is broken in snapshots when run near a foreign .packages file #25428

Closed
@nex3

Description

@nex3

This breakage appears under the following conditions:

  • The script contains a package: import.
  • The script uses Isolate.spawn().
  • The script is run from a snapshot.
  • The directory containing the snapshot, or a parent of that directory, contains a .packages file that's different from the one used to create the snapshot.

To reproduce this, create a package with the following files:

// bin/bin.dart
import 'dart:isolate';

import 'package:app/app.dart';

main() async {
  await Isolate.spawn(entrypoint, null);
}

void entrypoint(_) {
}
// lib/app.dart

// This file can be empty.
# pubspec.yaml
name: app

Run:

$ pub get
$ dart --snapshot=bin.dart.snapshot bin/bin.dart
$ rm .packages
$ touch .packages
$ dart bin.dart.snapshot

You should see an error like the following:

Unhandled exception:
IsolateSpawnException: Unable to spawn isolate: Unhandled exception:
Load Error for "package:app/app.dart": No mapping for 'app' package when resolving 'package:app/app.dart'.
#0      _asyncLoadErrorCallback (dart:_builtin:155)
#1      _asyncLoadError (dart:_builtin:566)
#2      _loadPackage (dart:_builtin:605)
#3      _loadData (dart:_builtin:637)
#4      _loadDataAsync (dart:_builtin:657)
#5      _loadScriptCallback (dart:_builtin:153)
#6      _handleLoaderReply (dart:_builtin:370)
#7      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:148)
'file:///tmp/app/bin/bin.dart': error: line 3 pos 1: library handler failed
import 'package:app/app.dart';
^
#0      Isolate.spawn.<spawn_async_body> (dart:isolate-patch/isolate_patch.dart)
#1      _asyncErrorWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:34)
#2      _RootZone.runBinary (dart:async/zone.dart:1154)
#3      _Future._propagateToListeners.handleError (dart:async/future_impl.dart:579)
#4      _Future._propagateToListeners (dart:async/future_impl.dart:641)
#5      _Future._completeError (dart:async/future_impl.dart:432)
#6      _SyncCompleter._completeError (dart:async/future_impl.dart:56)
#7      _Completer.completeError (dart:async/future_impl.dart:27)
#8      Isolate._spawnCommon.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:413)
#9      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:148)

This is a regression. Running git bisect indicates that this error appeared as of 6d066c7. It's likely related to dart-lang/pub#1379.

Metadata

Metadata

Assignees

Labels

P0A serious issue requiring immediate resolutionarea-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)vm-regression

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions