Skip to content

Illegal argument in isolate message : (function types are not supported yet) #44624

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

Closed
wustrong opened this issue Jan 9, 2021 · 5 comments
Closed
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-isolate

Comments

@wustrong
Copy link

wustrong commented Jan 9, 2021

This tracker is for issues related to:

  • Dart VM

  • Dart SDK Version (dart --version)
    Dart SDK version: 2.10.3 (stable) (Tue Oct 27 14:44:30 2020 +0100) on "linux_x64"

I tried to spawn a new isolate,but failed. I do not know why and how to figure it out . the error response like this:

startup tcp isolates failed, error: Invalid argument(s): Illegal argument in isolate message : (function types are not supported yet), stacktrace: #0 spawnFunction (dart:_internal-patch/internal_patch.dart:184:54)
#1 Isolate.spawn (dart:isolate-patch/isolate_patch.dart:380:7)
#2 IsolateServerTransport._spawn (package:trpc_dart/src/transport/isolate_server_transport.dart:38:35)
#3 IsolateServerTransport._spawnTCP (package:trpc_dart/src/transport/isolate_server_transport.dart:45:12)
#4 IsolateServerTransport.listenAndServeStream (package:trpc_dart/src/transport/isolate_server_transport.dart:60:39)
#5 DefaultServerTransport.listenAndServe (package:trpc_dart/src/transport/server_transport.dart:56:15)
#6 ServiceImpl.serve (package:trpc_dart/src/server/service.dart:138:28)
#7 Server.serve (package:trpc_dart/src/server/server.dart:56:19)
#8 main (file:///home/strongwu/code/trpc/trpc-dart/example/helloworld/bin/server.dart:23:18)
#9 _startIsolate. (dart:isolate-patch/isolate_patch.dart:299:32)
#10 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)

here is my code:

top-level or static method

void workerEntryPoint(IsolateWorker worker) {
  worker.start();
}

spawn

    final worker = IsolateWorker(ctx, lsOpts, id, receivePort.sendPort, networkType);
    final isolate = await Isolate.spawn(workerEntryPoint, worker, paused: true, debugName: id);

entrypoint message

class IsolateWorker {
  SendPort supervisingSendPort;

  ReceivePort supervisingReceivePort;

  // simple class
  Context ctx;

  // simple class
  ListenServeOptions lsOpts;

  String id;

  int networkType;

  Stream<Socket> _listener;

  RawDatagramSocket _udpConn;

  IsolateWorker(this.ctx, this.lsOpts, this.id, this.supervisingSendPort, this.networkType);

  Future start() async {
    supervisingReceivePort = ReceivePort();
    supervisingReceivePort.listen(listener);
    logger.info('IsolateServer($id) listening, sending port');
    supervisingSendPort.send(supervisingReceivePort.sendPort);
   ....
  }
}
@vsmenon vsmenon added library-isolate area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. labels Jan 10, 2021
@a-siva
Copy link
Contributor

a-siva commented Jan 13, 2021

We do not support sending of ReceivePort across isolates. In the example above when the isolate is spawned the 'worker' object is sent across. This object is of type IsolateWorker which has a ReceivePort field 'supervisingReceivePort'.
Maybe you could re structure your code to not have this field in the IsolateWorker class.

@wustrong
Copy link
Author

wustrong commented Jan 14, 2021

We do not support sending of ReceivePort across isolates. In the example above when the isolate is spawned the 'worker' object is sent across. This object is of type IsolateWorker which has a ReceivePort field 'supervisingReceivePort'.
Maybe you could re structure your code to not have this field in the IsolateWorker class.

@a-siva I dont send ReceivePort when spawn the worker, that supervisingReceivePort is new in start() method.

@wustrong
Copy link
Author

wustrong commented Jan 20, 2021

The reason is that the any field of object in message of entrypoint can not contain a Function type, as show in error.

feature support function type will be add new SDK version?

@a-siva

@mkustermann
Copy link
Member

@wustrong I suspect that either Context or ListenServeOptions will transitively have a function type or a closure (tracked at #40370) in it.

It is very easy to reproduce such cases:

import 'dart:isolate';

Type getType<T>() => T;
main() async => await Isolate.spawn(entrypoint, getType<void Function()>());
void entrypoint(dynamic x) {}

which results in

Invalid argument(s): Illegal argument in isolate message : (object is a FunctionType)

or

import 'dart:isolate';

Function getClosure() => () {};
main() async => await Isolate.spawn(entrypoint, getClosure());
void entrypoint(dynamic x) {}

which results in

Invalid argument(s): Illegal argument in isolate message : (object is a closure - Function '<anonymous closure>': static.)

Both of these issues we intend to fix with lightweight isolates (see #36097) which is nearing it's completion - so stay tuned :-)

@mkustermann
Copy link
Member

mkustermann commented Jul 15, 2021

Closing this issue, merge into the more general #46623.

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

No branches or pull requests

4 participants