Skip to content
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

No support for Isolate.resolvePackageUri #14815

Open
srawlins opened this issue Feb 22, 2018 · 19 comments

Comments

@srawlins
Copy link
Contributor

commented Feb 22, 2018

Steps to Reproduce

When running an app and calling Isolate.resolvePackageUri(), which I assumed would be safe on any platform, I see that it is an unsupported operation.

Logs

E/flutter (27891): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter (27891): Unsupported operation: Isolate.resolvePackageUri
E/flutter (27891): #0      initializeTimeZone.<anonymous closure> (package:timezone/standalone.dart:74:5)
E/flutter (27891): #1      _RootZone.runUnary (dart:async/zone.dart:1381)
E/flutter (27891): #2      _FutureListener.handleError (dart:async/future_impl.dart:144)
E/flutter (27891): #3      _Future._propagateToListeners.handleError (dart:async/future_impl.dart:645)
E/flutter (27891): #4      _Future._propagateToListeners (dart:async/future_impl.dart:666)
E/flutter (27891): #5      _Future._completeError (dart:async/future_impl.dart:485)
E/flutter (27891): #6      _SyncCompleter._completeError (dart:async/future_impl.dart:55)
E/flutter (27891): #7      _Completer.completeError (dart:async/future_impl.dart:27)
E/flutter (27891): #8      _loadAsBytes (package:timezone/standalone.dart)

Question

Is it intentionally unsupported? Or is it just not supported yet? I could not find any documentation on this.

@cbracken

This comment has been minimized.

Copy link
Member

commented Feb 23, 2018

/cc @a-siva

@a-siva

This comment has been minimized.

Copy link
Contributor

commented Feb 23, 2018

On the command line VM the embedder sets up the VMLibraryHooks class which has the resolvePackageUri functionality by calling into the '_setupHooks' method in builtin.dart.
For some reason we don't do the same in flutter engine, need to investigate why.

@pedzed

This comment has been minimized.

Copy link

commented Aug 15, 2018

Any updates on this?

@chenasraf

This comment has been minimized.

Copy link

commented Feb 26, 2019

Also have this problem, trying to use my own package which uses a static data json file - I can't load it, via File nor the Resource package.

@acherkashyn

This comment has been minimized.

Copy link

commented Apr 17, 2019

Also getting this error when trying to run tests with mock_web_server with TLS certificate.

Unsupported operation: Isolate.resolvePackageUri

dart:isolate                              Isolate.resolvePackageUri
package:resource/src/resolve.dart 11:20   resolveUri
package:resource/src/resource.dart 64:21  Resource.readAsBytes
===== asynchronous gap ===========================
dart:async                                _AsyncAwaitCompleter.completeError
package:resource/src/resource.dart        Resource.readAsBytes

Any progress on this issue?

@eseidelGoogle

This comment has been minimized.

Copy link
Contributor

commented Apr 25, 2019

https://pub.dartlang.org/packages/path_provider or https://docs.flutter.io/flutter/services/AssetBundle-class.html might be the path-lookups you're looking for. https://flutter.dev/docs/development/ui/assets-and-images

I'm not sure whether this was intentional or not. But it's also not immediately clear to me what this API should do in Flutter?

@ened

This comment has been minimized.

Copy link
Contributor

commented Apr 30, 2019

@eseidelGoogle Isolate.spawn seems to be using it:

From current testing, this prevents background Isolates on iOS (created using FlutterEngine(name: "MyIsolate", project: nil, allowHeadlessExecution: true)) from creating further child Isolates themselves.

@ened

This comment has been minimized.

Copy link
Contributor

commented Apr 30, 2019

Related to rmawatson/flutter_isolate#5 - this is a major headache now.

@ened

This comment has been minimized.

Copy link
Contributor

commented May 7, 2019

Adding on - code that relies on executing compute calls to lift tasks out of the main thread will also not run in the iOS background.

@liamappelbe

This comment has been minimized.

Copy link
Contributor

commented May 7, 2019

@a-siva Actually Flutter doesn't use dart:_builtin. Flutter's equivalent of _builtin is ui/natives.dart, and that library's _setupHooks() method is called during setup here.

So I think the issue here is that there's some functionality missing from ui/natives.dart required to make Isolate.resolvePackageUri work.

@ened

This comment has been minimized.

Copy link
Contributor

commented May 8, 2019

@liamappelbe is it an easy fix?

@liamappelbe

This comment has been minimized.

Copy link
Contributor

commented May 8, 2019

Not sure yet. Still investigating.

@liamappelbe

This comment has been minimized.

Copy link
Contributor

commented May 9, 2019

Looks like we can't just naively copy the implementation that dart uses. We'll need to implement something custom.

@cbracken Any ideas about what this API should do on Flutter? It's supposed to turn "package:" URIs into absolute URIs. For example, when I run this on Linux I get an absolute path to the dart file of the package. Does that make sense on all Flutter platforms?

@ened

This comment has been minimized.

Copy link
Contributor

commented May 15, 2019

@liamappelbe apps are stored in containers on iOS, so it would make sense to resolve to the absolute path of filesystem + container?

@liamappelbe liamappelbe assigned a-siva and unassigned liamappelbe May 20, 2019
@lrhn

This comment has been minimized.

Copy link

commented Jun 6, 2019

The entire "package URI resolution" does not make sense for AOT compilation. It assumes that source files are available at run-time, and then further assumes that other files can be found next to them. This model works fine for programs distirbuted as source, but an AOT-compiled program has no need to replicate the source directory structure anywhere.

One option is to include resources in the binary in a virtual file system, and resolve package URIs for those resources to internal URIs like dart-resource://packagename/foo/bar.txt. Some code may fail to handle that because it assumes file URIs, but we never promised that.
It does mean that the build step will have to have a way to specify resource files (or maybe just assume that any non-.dart file in a lib/ directory is a resource, but you probably still want to be able to tree-shake resources.

@ened

This comment has been minimized.

Copy link
Contributor

commented Jun 6, 2019

This is starting to sound like code smell for the Isolate.spawn mechanism? Why would it require access to resources, by default & thus prevent the spawn itself?

@lrhn

This comment has been minimized.

Copy link

commented Jun 6, 2019

The Isolate.spawn function should not require anything which is not already available for the cloned isolate. It really should just clone the current isolate's code (reinitializing global variables), and then run the specified function.

It's Isolate.spawnUri that is not really meaningful for AOT-compiled code. You have to have a compiled image ready for the given target URI, and you don't actually use that URI for anything except looking up the image. It would make more sense to have a "resource"/"asset" concept, and make compiled isolate images a resource made available by the deployment system, not something referenced by source URI.

@ened

This comment has been minimized.

Copy link
Contributor

commented Jun 27, 2019

@lrhn how to move on from here? Based on your comment and the source code visible at https://api.flutter.dev/flutter/foundation/compute.html, the Flutter compute function should simply work?

@lrhn

This comment has been minimized.

Copy link

commented Jun 27, 2019

I see no issue in that code either (from a cursory reading), so I'm not sure what you are asking about.

If the Isolate.resolvePackageUri function doesn't work, then it's not because of this code, but an underlying issue in the Flutter isolate set-up phase, as discussed above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.