-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Allow sending more kinds of objects between isolates #46623
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
Comments
Does anyone works on this? Is there any info when we will be able to send Function types? |
Yes, we are actively working on it. We are in preparation for enabling lightweight isolates by-default (see #36097). After that doing that, allowing more object types to be sent between isolates is a piece of cake. |
If you can send closures, that will open up sending a lot of low-level classes, like If you send a stream pre-listening, it will include its controller and the There might be cases where you do want to send a primed stream to a worker isolate, to make it take over, as long as you don't use it locally, so maybe strictly making streams non-sendable isn't the best approach. |
Sending a https://www.chromestatus.com/feature/5298733486964736#details |
Summary of meeting about sending closures (between @aam @lrhn and @mkustermann ):
There's a question of how much state a local closure closes over. Right now the VM's implementation closes over more state than needed (an implementation choice) that can lead to hanging on to more objects than user code can access (though a debugger might be able to access them). See e.g. #36983. Allowing sending of closures may make this "memory leak" more prominent. In general there's no strong reservations against loosing that restriction. |
We already allow sending closures (if immutable via sharing otherwise via copying). This CL makes use of this to allow the argument to `Isolate.spawn()` to be any closure. Similar to normal message sending, the spawn will fail if the closure cannot be sent (or causes an error on the new isolate, e.g. rehashing error). Issue #46623 TEST=vm/dart{_2,}/isolates/closure_entrypoint_test Change-Id: Iab342267d87bd87bc8c0c82d16aec58a69a3df44 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212295 Reviewed-by: Alexander Aprelev <[email protected]> Commit-Queue: Martin Kustermann <[email protected]>
As a small update: This has mostly been adressed (closures, function types, ... can be sent now across |
Wow this is excellent news @mkustermann ! Is using closures as |
@maks Yes it is. (it's |
The existing lib/isolate/stacktrace_message_test was failing and also incorrectly written due to "!" in front of the expected stringification of the stacktrace. Issue #46623 TEST=vm/dart{,_2}/isolates/fast_object_copy2_test, lib{,_2}/isolate/stacktrace_message_test Change-Id: I169d8fd7a7c3cb3b8c57e00287565e3a5c622acf Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/216041 Reviewed-by: Alexander Aprelev <[email protected]> Commit-Queue: Martin Kustermann <[email protected]>
So has it been scheduled as part of the dart 2.15 release? And if so when do we expect to see dart 2.15? |
Yes, no fixed date, but "towards the end of the year" is a good estimate. |
…cise In addition to making the documentation of [SendPort.send] more precise by describing what objects are disallowed for sending objects between isolates within the same isolate group, it also makes [Isolate.exit] link to [SendPort.send]. Closes #46623 TEST=Updates documentation only. Change-Id: I9bc1d88faaf2b70589af5e56168976ba89a35558 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/219080 Commit-Queue: Martin Kustermann <[email protected]> Reviewed-by: Alexander Aprelev <[email protected]>
fix generated test issue tweak yml no private Fix a problem with compiling contorller with List parameter Update conduit/lib/src/runtime/resource_controller_impl.dart workflow tweaks bug fixing test-harness update yml commands change closure test to UserTag as per dart-lang/sdk#46623 cache sources fix port issue try dev channel switch around agents wtf wtf
* refactor: use melos for mono-repo management * chore(release): publish packages - [email protected] - [email protected] - [email protected] - [email protected] - [email protected] - [email protected] - [email protected] - [email protected] - [email protected] - [email protected] * introduce melos, minor fixups, tweak CI * catch HttpException * Fix a problem with compiling contorller with List parameter * Update conduit/lib/src/runtime/resource_controller_impl.dart * change closure test to UserTag as per dart-lang/sdk#46623 * Fix dart2native compile command (#76) Fix a problem with compiling contorller with List parameter Update conduit/lib/src/runtime/resource_controller_impl.dart change closure test to UserTag as per dart-lang/sdk#46623 * chore(release): publish packages - [email protected] - [email protected] Co-authored-by: Slavi Boyanov <[email protected]> Co-authored-by: Vladi Rachlin <[email protected]>
I try to send
Any solution to that? |
@adamstyrc See my reply here #38964 (comment) The idea behind isolates is that they are isolated from each other, cannot see side-effects of another isolate and communicate purely via message passing. Sending native resources such as a So it is intentional to disallow this. What you can do is to make the isolate create network I/O and forward individual messages to the main isolate (if those messages do not contain native resources). |
@mkustermann I wonder if we could consider adding helpers to // Send socket to another isolate. Native socket gets detached from the
// Dart object. Calling methods on [socket] will cause [DetachedError] and
// no events will be delivered through [socket] stream.
port.send(detached(socket)); |
@mraleph The thought has crossed my mind before - doing something similar to our existing transferrable bytedata Here's the issues that made us not look too much into this so far:
I think overall our current transitive-copy approach may be in sufficient due to these things. In the past I have thought that some of these problems could be avoided by letting users control what happens on a send of an object. Objects could e.g. implement @mraleph Would you suggest baking in |
The situation may be easier for |
Thanks @mkustermann for your comprehensive statement! :) |
@mkustermann thanks for your detailed response! For me the use-case with websockets is to share incoming connections out to large numbers of (possibly short lived) Isolates. So I'm unclear if that would be possible currently? Also per the above, I wouldn't find passing Isolates out of exiting Isolates very useful, so I wouldn't be voting for any work to get that implemented. |
@maks, |
thanks for the explanation @aam. I guess this might need to go into a separate issue: but is the way the incoming requests are distributed amongst multiple Isolates documented anywhere? In the docs it only says:
|
Not sure whether documentation is vague on purpose not to pin current implementation down, but currently incoming requests are distributed in round-robin order between all |
We would like to be able to loosen the current requirements on objects that can be sent between isolates through
SendPort
s. We can solve this once lightweight isolates are enabled by-default (see #36097) - which is slowly coming to its finishing line.We want to allow sending:
lib_2/isolate/stacktrace_message_test
fails)Furthermore we want to:
SendPort
s.Once lightweight isolate support (see #36097) has been enabled by-default (probably soon), we can easily add this support.
The text was updated successfully, but these errors were encountered: