Skip to content

Isolate.spawn is broken in snapshots when the original .packages file is missing #25429

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 original directory containing the snapshot has neither a .packages file nor a packages/ directory.

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
$ rm -r 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": Could not resolve a package location for base at file:///tmp/app/bin/bin.dart
#0      _asyncLoadErrorCallback (dart:_builtin:155)
#1      _asyncLoadError (dart:_builtin:566)
#2      _loadPackage (dart:_builtin:605)
#3      _loadPackage.<anonymous closure> (dart:_builtin:621)
#4      _handlePackagesReply (dart:_builtin:464)
#5      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:148)
#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)

It's worth noting that the error is the same regardless of whether the snapshot file is copied to, indicating that it somehow remembers its original location. It's not clear why this is, and it could be construed as a security risk if the file system path of the build system is sensitive for some reason.

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

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @nex3@kevmoo@iposva-google

      Issue actions

        Isolate.spawn is broken in snapshots when the original .packages file is missing · Issue #25429 · dart-lang/sdk