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
SendPort.send should only accept "literal-like" objects. #21398
Comments
This comment was originally written by @zoechi Currently it's also possible to send arbitrary Dart objects at least on the server (when they don't import native libraries). Should this be removed? I thought this should be added on the client too instead. |
This only applies to ports between isolates that haven't been created using Isolate.spawn from the same root isolate. |
Set owner to @a-siva. |
When we do this, let's also update the dartdocs on SendPort (which currently implies you in "special circumstances" you can send over objects). Thanks! |
There's a current bug, which fails silently. If we change SendPort.send to only send literal-like objects, then this bug will be addressed (I assume). In the meantime, the following code will NOT print 'here', and no exception or error is thrown or detected: import 'dart:isolate'; class FromMainIsolate { main() { Isolate.spawnUri(Uri.parse('loadme.dart'), [], receive.sendPort).then((isolate) { } import 'dart:isolate'; //import 'shared.dart'; class FromChildIsolate { main(List<String> args, message) { |
FWIW it's very confusing if SendPort's behavior/capability is different if it comes in via either spawn or spawnUri. The user of the SendPort doesn't know if it came from spawn or spawnUri. There's no way (afaict) to ask "can I send an arbitrary object via this SendPort?" |
It is confusing, but the difference is already there - currently it just crashes if you send objects to an isolate where the class isn't loaded. We could add a boolean getter on SendPort that tells you whether the receiving port is in an equivalent isolate (spawned from the same isolate through Isolate.spawn calls). It might even be a good idea, and it can be done fairly efficiently. It's actually not clear from this issue's description what the VM should do when sending to a non-equivalent isolate. Dart2js does something similar to JSON encoding, so any List becomes a default (Growable)List, any Map becomes a default (LinkedHash)Map when deserialized, no matter what kind they were before. |
Added Accepted label. |
Issue #15983 has been merged into this issue. |
When sending objects through send-ports, only literal-like objects should be sent.
That is:
I should handle object cycles.
It's not clear whether a fixed-length List should preserve it's fixed-lengthness (it doesn't in dart2js), or how a user-defined class implementing List should be handled (dart2js converts to normal List).
Similar for maps - what happens for an identity-HashMap, SplayTreeMap or a user defined map isn't clear. The simplest solution is to convert all to a basic LinkedHashMap.
(When sending to isolates with the same classes - as created by Isolate.spawn from the same root - we also want to extend this with top-level/static functions).
The text was updated successfully, but these errors were encountered: