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

print silently kills spawnUri isolate in Dartium #14080

Closed
DartBot opened this issue Oct 14, 2013 · 19 comments
Closed

print silently kills spawnUri isolate in Dartium #14080

DartBot opened this issue Oct 14, 2013 · 19 comments
Assignees

Comments

@DartBot
Copy link

DartBot commented Oct 14, 2013

This issue was originally filed by kbecker81...@gmail.com


What steps will reproduce the problem?
There is a file test.dart:
import 'dart:isolate';

void main(){
  port.receive((String map, SendPort send){
    print("Received: $map");
    send.send("Test");
  });
}

A file server.dart:
import 'dart:async';
import 'dart:io';

void main() {
  HttpServer.bind("localhost", 9998)
      .then((server) {
        print("http://${server.address}:${server.port}/");
        server.listen(
            (request) {
// request.response.headers.set(HttpHeaders.CONTENT_TYPE, "application/dart");
              new File("test.dart").openRead().pipe(request.response);
            });
      });
}

A command line test:
import 'dart:isolate';

void main(){
  var spawn=spawnUri("http://localhost:9998/");
  spawn.call("Hallo").then((map){
     print(map);
  });
}

And a web test (with all the example application stuff and this dart file):
import 'dart:html';
import 'dart:isolate';

void main() {
  query("#sample_text_id")
    ..text = "Click me!"
    ..onClick.listen(reverseText);
}

void reverseText(MouseEvent event) {
  var spawn=spawnUri("http://localhost:9998/");
  spawn.call("Hallo").then((map){
     print(map);
     query("#sample_text_id").text = map.toString();
  });
}

What is the expected output? What do you see instead?
The output of the web version should be the same as the web version:
Received: Hallo
Test

What version of the product are you using? On what operating system?
Dart SDK version 0.8.1.2_r28355 on MacOS X

The only message you get is that the script is transferred as text/plain, but I also tried application/dart which did not change anything..

@madsager
Copy link
Contributor

Is this running in dartium or compiled with dart2js?


Added Area-Library, Triaged labels.

@DartBot
Copy link
Author

DartBot commented Oct 16, 2013

This comment was originally written by kbec...@gmail.com


In dartium.

The dart2js Version that spawns with the compiled JavaScript version works.


Sent from Mailbox for iPad

@floitschG
Copy link
Contributor

We recently modified the spawnUri/spawnFunction in Dartium, but normally this should still work.
I will see if I can take a look.


cc @vsmenon.
Added Library-Isolate label.

@floitschG
Copy link
Contributor

Haven't yet have the time to really investigate, but Vijay told me that "print" currently relies on the DOM and is therefore not available in spawnUri threads (which don't have access to the DOM).
We will probably implement a work-around, but it might take a few days.

@DartBot
Copy link
Author

DartBot commented Oct 17, 2013

This comment was originally written by kbecker...@gmail.com


The problem is not that the isolate can not print (which is annoying as well), but the isolate sends back data, the String "Test" which is not done. So the isolate is not responding at all..

@floitschG
Copy link
Contributor

Just reproduced. It seems like calling "print" in the spawned isolate will silently kill the isolate. After removing the print I got the message back.

Changing title of bug accordingly.


Changed the title to: "print silently kills spawnUri isolate in Dartium".

@DartBot
Copy link
Author

DartBot commented Oct 17, 2013

This comment was originally written by kbec...@gmail.com


Ah, thanks! That was causing the problem. I was able to work around that by eliminating the print statements. Now it works as expected. Well except that debugging of isolates is now close to impossible ;)

@floitschG
Copy link
Contributor

For now the easiest work-around is to overwrite "print" with a function that sends the message to the other side:

in the DOM isolate:
var printReceiver = new ReceivePort();
printReceiver.receive((msg, _) { print(msg); });

otherIsolatePort.send(printReceiver.toSendPort());

-- in the other Isolate:
var _globalPrintPort;

main() {
  // somehow receive the printPort:
  _globalPrintPort = ...;
}

print(o) { _globalPrintPort.send(o.toString()); }

It's not optimal, but at least it should get you going (and this is probably what we are going to do behind the scenes).

@DartBot
Copy link
Author

DartBot commented Nov 5, 2013

This comment was originally written by @filiph


I understand this is not simple to fix properly, but a huge improvement would be if:

a) calling print() in an isolate would just be ignored, or
b) the isolate would not crash silently, but with a loud bang (preferable including stack trace).

Right now, debugging a complex isolate is a nightmare. And since there was the recent major change in the dart:isolate library (https://plus.google.com/+dartlang/posts/NF6AJ3oPYuk), that's a lot of nightmares out there.

@dgrove
Copy link
Contributor

dgrove commented Nov 6, 2013

Issue #14800 has been merged into this issue.

@DartBot
Copy link
Author

DartBot commented Jan 13, 2014

This comment was originally written by salgat...@gmail.com


This problem gave me a lot of headaches last night, was finally able to isolate it down to this reason. Good to see it confirmed here. filip.hr has a good point that print should be ignored for the time being.

@sethladd
Copy link
Contributor

Should this be reclassified as Dartium?

@floitschG
Copy link
Contributor

cc @lrhn.

@sethladd
Copy link
Contributor

sethladd commented Jun 4, 2014

Issue #19170 has been merged into this issue.

@a-siva
Copy link
Contributor

a-siva commented Aug 18, 2014

Issue #16402 has been merged into this issue.

@vsmenon
Copy link
Member

vsmenon commented Aug 26, 2014

Issue #14067 has been merged into this issue.


cc @jacob314.

@floitschG
Copy link
Contributor

Issue #21877 has been merged into this issue.

@floitschG
Copy link
Contributor

@ivan: I will talk to Lasse tomorrow to see if there is a work-around, but this really should be fixed at the Dartium level (which is why I reassigned the Area).

A similar issue #21925 fails because of the same restrictions (there because of missing Timers).


cc @iposva-google.
cc @a-siva.
Removed Area-Library label.
Added Area-Dartium label.

@alan-knight
Copy link
Contributor

I also created 22163 for this. It might be a duplicate. The problem is not that it silently kills the isolate, it throws with a clear error message which then gets discarded. Possibly the root problem is that setting up isolate exception handling is hard. But print should also just work.

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

No branches or pull requests

9 participants