Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nex3 opened this issue Jan 14, 2016 · 3 comments
Closed
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P0 A serious issue requiring immediate resolution type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) vm-regression
Milestone

Comments

@nex3
Copy link
Member

nex3 commented Jan 14, 2016

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.

@nex3 nex3 added Type-Defect area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P0 A serious issue requiring immediate resolution vm-regression labels Jan 14, 2016
@nex3 nex3 added this to the 1.14 milestone Jan 14, 2016
@lrhn
Copy link
Member

lrhn commented Jan 14, 2016

Doing Isolate.spawn should not read any files. It should run with exactly the same source and configuration as the isolate that calls spawn. If it rereads source files, that's no longer guaranteed, and if it's not running the same code, object transfer between the isolates may fail when the classes are no longer identical (or even there).
The new isolate should really be close to a "fork" of the original isolate - as it was just before running main.

@nex3
Copy link
Member Author

nex3 commented Jan 14, 2016

@lrhn That's been an issue for a long time; see #6610.

@iposva-google
Copy link
Contributor

Fixed: https://codereview.chromium.org/1591573004

Duplicate of #25430

@kevmoo kevmoo added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed Type-Defect labels Mar 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P0 A serious issue requiring immediate resolution type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) vm-regression
Projects
None yet
Development

No branches or pull requests

4 participants