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

Closures over-capture, cannot be sent to other isolate. #52661

Closed
Silfalion opened this issue Jun 9, 2023 · 3 comments
Closed

Closures over-capture, cannot be sent to other isolate. #52661

Silfalion opened this issue Jun 9, 2023 · 3 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends.

Comments

@Silfalion
Copy link

Silfalion commented Jun 9, 2023

Hello! I'm trying to create a FormData from a Map<String, dynamic> but I'm faced with the error:

Invalid argument(s): Illegal argument in isolate message: object is unsendable - Library:'dart:async' Class: _Future@4048458 (see restrictions listed at `SendPort.send()` documentation for more information)
I/flutter (18310):  <- Instance of '_HttpClientConnection' (from dart:_http)
I/flutter (18310):  <- Instance of '_HashSetEntry<_HttpClientConnection>' (from dart:collection)
I/flutter (18310):  <- _List len:8 (from dart:core)
I/flutter (18310):  <- Instance of '_HashSet<_HttpClientConnection>' (from dart:collection)
I/flutter (18310):  <- Instance of '_ConnectionTarget' (from dart:_http)
I/flutter (18310):  <- Instance of '_HashMapEntry<String, _ConnectionTarget>' (from dart:collection)
I/flutter (18310):  <- _List len:8 (from dart:core)
I/flutter (18310):  <- Instance of '_HashMap<String, _ConnectionTarget>' (from dart:collection)
I/flutter (18310):  <- Instance of '_HttpClient' (from dart:_http)

Very sorry, the only code I'm able to share is the following:

`final result = await compute((m)=>exportToFormData(mapOfFields), 'hi');

The function returns a Future.

I'm not able to share much more, but the case is very similar to this one(which has a code sample):

flutter/flutter#126520

@lrhn
Copy link
Member

lrhn commented Jun 9, 2023

This sounds like your closure is over-capturing, which is a known problem with the VM's implementation of closures.
Try moving the creation of the closure into another, function, say:

// Declared somewhere, top-level or static.
Future<WhateverItIs> _computeExport(Map<String, String> data) => compute((_) => exportToForm(data), 'hi');
...
  // Then use as:
  final result = await _computeExport(mapOfFields);

@lrhn lrhn added the area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. label Jun 9, 2023
@lrhn lrhn changed the title Create an issue Closures over-capture, cannot be sent to other isolate. Jun 9, 2023
@Silfalion
Copy link
Author

Got it, will give it a shot. Thank you

@InMatrix InMatrix assigned InMatrix and unassigned InMatrix Jun 9, 2023
@mkustermann
Copy link
Member

We have an older open issue regarding the over-capturing of closures. Will close this in favor of #36983.

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.
Projects
None yet
Development

No branches or pull requests

4 participants