dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.23k stars 1.58k forks source link

spawnUri fails on chrome #25597

Closed TastyCatFood closed 6 years ago

TastyCatFood commented 8 years ago

What happens: chrome throws an error.

What causes it: var isolate = Isolate.spawnUri(Uri.parse('skulpt_interface.dart'), [],port.sendPort);

Where it happens: on chrome browser but not on dartium

Cause

The cause of the error was as I posted separately below(leaving this post because I don't want to retype everything). Link to the project with the problem reproduced:https://github.com/TastyCatFood/dart-isolate-error-reproduced It calls Isolate.spawnUri in the file index.dart

Error(on chrome) ////////////////////// Uncaught Error spawning worker for skulpt_interface.dart.js dart.a @ js_helper.dart:1697 dart.nB.$0 @ zone.dart:895 dart.h3.eK @ future_impl.dart:579 dart.ns @ schedule_microtask.dart:43 dart.qE @ schedule_microtask.dart:52 dart.lR.$1 @ async_patch.dart:53 dart.oy.$0 @ js_helper.dart:2373 dart.cw.aQ @ isolate_helper.dart:462 dart.bN @ isolate_helper.dart:54 dart.ow @ js_helper.dart:2373 (anonymous function) @ js_helper.dart:2397 ////////////////////////////

Dartium prints ////////////////////////////// isolate running terminating /////////////////////

The code:

library isolate;
import 'dart:isolate';

void main(args,SendPort sp){ sp.send('isolate running'); sp.send('terminating'); }

Caller:


    var port = new ReceivePort();
    var isolate = Isolate.spawnUri(
        Uri.parse(
          'skulpt_interface.dart'),
        [],port.sendPort);
    port.listen(print); 
Versions: dart --version Dart VM version: 1.13.0 (Wed Nov 18 12:24:20 2015) on "windows_x64" dart2js --version Dart-to-JavaScript compiler (dart2js) version: 1.13.0
alan-knight commented 8 years ago

If you catch the error it might tell you more useful information.

TastyCatFood commented 8 years ago

Hi alan-knight, thank you so much for your comment.

I found a clue, but it's hard. The worst part of this issue is that dart2js does not always print the error message. Also, the problem should not surface as an unhandled exception, but it does.

The build error (you get this only if you are LUCKY, I can't remember how I could get this at all): ////////////// Transform Dart2JS on quiz|web/index.bootstrap.initialize.dart threw error: Internal Error: The library 'dart:_js_helper' does not contain required element: '_Patch'. package:compiler_unsupported/src/compiler.dart 1827 _CompilerDiagnosticReporter.internalError package:compiler_unsupported/src/compiler.dart 758 Compiler.findRequiredElement package:compiler_unsupported/src/compiler.dart 613 Compiler.onLibraryScanned package:compiler_unsupported/src/library_loader.dart 444 _LibraryLoaderTask.processLibraryTags. _LibraryLoaderTask.processLibraryTags. Build failed. ////////////////////

The culprit

$include: '*/.bootstrap.initialize.dart' Removing the line above fixed the problem. A nasty silent emerging bug... My pubspec.yml (Intellij's default polymer configuration minus a few things to find the cause)


name: 'quiz'
version: 0.0.1
description: A web app built using polymer.dart.
#author: Your Name 
#homepage: https://www.example.com
environment:
  sdk: '>=1.9.0 <2.0.0'
dependencies:
  browser: ^0.10.0
#  polymer_elements: ^1.0.0-rc.1
#  polymer: ^1.0.0-rc.2
  reflectable: ^0.3.1
  web_components: ^0.12.0
transformers:
- web_components:
    entry_points: web/index.html
- reflectable:
    entry_points: web/index.bootstrap.initialize.dart
- $dart2js:
    $include: '**/*.bootstrap.initialize.dart'
    minify: true
    commandLineOptions:
    - --trust-type-annotations
    - --trust-primitives

As to your suggestion to catch: Call stack had "dart.h2.eL @ future_impl.dart:579", so the exception was bypassing my code.

The only error handling resource I could find for isolate on the web is: http://stackoverflow.com/questions/24550403/how-to-pass-message-to-isolate-and-handle-error A little short of info and the tutorial does not cover isolate at all.

alan-knight commented 8 years ago

You can't catch errors in spawn with normal exception handling because it's creating a different stack. You need to use the onError parameter in spawnUri, and/or the Future.catchError method.

And yes, catching these errors is very painful.

TastyCatFood commented 8 years ago

Hi, alan-knight. The exception occurs at the initialization time on CHROME(dartium is happy) or dart2js. Not on call time. The generated Call stack does not include any of my code. $include: '*/.bootstrap.initialize.dart' in pubspec causes the exception.

I have uploaded the example code that throws the error and I'm sure I lack the knowledge of dart-sdk internal to properly explain what is happening.

Please have a look. Link to the project with the problem reproduced:https://github.com/TastyCatFood/dart-isolate-error-reproduced It calls Isolate.spawnUri in the file index.dart

kevmoo commented 6 years ago

Browser support for Isolate has been dropped in Dart2