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

VM: Implement Isolate.kill #21189

Closed
lrhn opened this issue Oct 1, 2014 · 7 comments
Closed

VM: Implement Isolate.kill #21189

lrhn opened this issue Oct 1, 2014 · 7 comments
Assignees
Labels
Milestone

Comments

@lrhn
Copy link
Member

lrhn commented Oct 1, 2014

Make it possible to shut down an isolate by calling Isolate.kill.

@sgjesse
Copy link
Contributor

sgjesse commented Nov 13, 2014

Marked this as blocking #21599.

@sgjesse
Copy link
Contributor

sgjesse commented Nov 13, 2014

Added this to the 1.9 milestone.

@iposva-google
Copy link
Contributor

Issue #21053 has been merged into this issue.

@iposva-google
Copy link
Contributor

With https://codereview.chromium.org/800713002 I can run:

import "dart:isolate";
import "dart:async";

isolateMain(loopForever) {
  if (loopForever){
    var i = 0;
    while (true) {
      if (i == 0) {
        print("remote");
      }
      i = (i + 1) & 0x1ffffff;
    }
  } else {
    new Timer.periodic(new Duration(milliseconds: 100), (_) {
      print("isolateMain");
    });
  }
}

printUsage() {
  throw "Usage: dart Killer.dart forever|event";
}

main(args) {
  // Check which mode is requested.
  if (args.length < 1) {
    printUsage();
  }
  var loopForever;
  if (args[0] == "forever") {
    loopForever = true;
  } else if (args[0] == "event") {
    loopForever = false;
  } else {
    printUsage();
  }

  // Spawn the isolate.
  Isolate.spawn(isolateMain, loopForever).then((isolate) {
    print("remote Isolate started");
    // Let the isolate run for 4 seconds and then request termination.
    new Timer(new Duration(seconds: 4), () {
      print("Chicken!"); // Kylling the isolate.
      isolate.kill(loopForever? Isolate.IMMEDIATE : Isolate.AS_EVENT);
    });

    // Keep pinging the isolate. Only exit if the isolate stops responding
    // to pings, which is equivalent to it having been terminated.
    var pongTimer;
    var pongPort = new RawReceivePort();
    pongPort.handler = (_) {
      pongTimer.cancel();
      pongTimer = null;
      print("alive");
    };
    new Timer.periodic(new Duration(milliseconds: 200), (timer) {
      // Start a new timer which waits for the reply of the ping.
      pongTimer = new Timer(new Duration(milliseconds: 5), () {
        print("No Pong received: Exiting.");
        timer.cancel();
        pongPort.close();
      });
      isolate.ping(pongPort.sendPort, Isolate.IMMEDIATE);
    });
  });
}


Set owner to @iposva-google.
Added Started label.

@sgjesse
Copy link
Contributor

sgjesse commented Dec 12, 2014

Sounds good.

We also need to deal with all the external resources an isolate has allocated, e.g. open file descriptors.

Also something comes back to me regarding the native isolate and handling of responses to outstanding operations which completed for an isolate which is now killed. At some point we talked about a queue for handling these messages, so that the operation can be "undone" to avoid resource leak. If open file completed the file must be closed

@iposva-google
Copy link
Contributor

Fixed in r42355

Re: comment 5: Messages originating from C code can contain a redirection port, so the IO code just needs to hook into this API.


Added Fixed label.

@sethladd
Copy link
Contributor

Marked this as blocking #22067.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants