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.26k stars 1.58k forks source link

[WASM] RuntimeError: illegal cast #55868

Closed brian-superlist closed 5 months ago

brian-superlist commented 5 months ago

We experience runtime errors while running our app app in-browser with WASM support.

Unfortunately, our app is quite large and I wasn't able to boil this down to a minimal reproduction step right now, but I saw a similar issue (#55513). We also cannot share source code as it is a closed source application (Superlist)

Reproduction steps

  1. Build app with wasm support: flutter build web --release --dart-define="SIGN_IN_CONTINUE_URL=http://app.superlist.com" --build-name="ABC" --build-number="XYZ" --source-maps --wasm --no-strip-wasm --target lib/main_prod.dart
  2. Host app on a provider with the correct headers or locally with dart pub global run dhttpd '--headers=Cross-Origin-Embedder-Policy=credentialless;Cross-Origin-Opener-Policy=same-origin'
  3. Open app in Chrome Version 125.0.6422.112 (Official Build) (arm64) on MacOS Sonoma 14.5 (23F79)

Expected Result

App runs with wasm support!

Actual Result

The app does not run. The following error is displayed in the console.

main.dart.wasm:0x48b1fb Uncaught RuntimeError: illegal cast
    at Auth.onWaitInitState inner (main.dart.wasm:0x48b1fb)
    at _awaitHelperWithTypeCheck closure at org-dartlang-sdk:///dart-sdk/lib/_internal/wasm/lib/async_patch.dart:97:16 (main.dart.wasm:0x485bd8)
    at closure wrapper at org-dartlang-sdk:///dart-sdk/lib/_internal/wasm/lib/async_patch.dart:97:16 trampoline (main.dart.wasm:0x485cdf)
    at _rootRunUnary (main.dart.wasm:0x48686a)
    at _CustomZone.runUnary (main.dart.wasm:0x583189)
    at _Future._propagateToListeners (main.dart.wasm:0x486420)
    at _Future._completeWithValue (main.dart.wasm:0x486ad7)
    at _Future._asyncCompleteWithValue closure at org-dartlang-sdk:///dart-sdk/lib/async/future_impl.dart:721:29 (main.dart.wasm:0x48bccf)
    at closure wrapper at org-dartlang-sdk:///dart-sdk/lib/async/future_impl.dart:721:29 trampoline (main.dart.wasm:0x48bce5)
    at _rootRun (main.dart.wasm:0x484d71)
$Auth.onWaitInitState inner @ main.dart.wasm:0x48b1fb
$_awaitHelperWithTypeCheck closure at org-dartlang-sdk:///dart-sdk/lib/_internal/wasm/lib/async_patch.dart:97:16 @ main.dart.wasm:0x485bd8
$closure wrapper at org-dartlang-sdk:///dart-sdk/lib/_internal/wasm/lib/async_patch.dart:97:16 trampoline @ main.dart.wasm:0x485cdf
$_rootRunUnary @ main.dart.wasm:0x48686a
$_CustomZone.runUnary @ main.dart.wasm:0x583189
$_Future._propagateToListeners @ main.dart.wasm:0x486420
$_Future._completeWithValue @ main.dart.wasm:0x486ad7
$_Future._asyncCompleteWithValue closure at org-dartlang-sdk:///dart-sdk/lib/async/future_impl.dart:721:29 @ main.dart.wasm:0x48bccf
$closure wrapper at org-dartlang-sdk:///dart-sdk/lib/async/future_impl.dart:721:29 trampoline @ main.dart.wasm:0x48bce5
$_rootRun @ main.dart.wasm:0x484d71
$_rootRun tear-off trampoline @ main.dart.wasm:0x583b36
$_CustomZone.run @ main.dart.wasm:0x5831e4
$_CustomZone.runGuarded @ main.dart.wasm:0x5833e5
$_CustomZone.bindCallbackGuarded closure at org-dartlang-sdk:///dart-sdk/lib/async/zone.dart:1249:12 @ main.dart.wasm:0x583da6
$closure wrapper at org-dartlang-sdk:///dart-sdk/lib/async/zone.dart:1249:12 trampoline @ main.dart.wasm:0x583dbd
$_startMicrotaskLoop @ main.dart.wasm:0x484f46
$_startMicrotaskLoop tear-off trampoline @ main.dart.wasm:0x484fb1
$_invokeCallback @ main.dart.wasm:0x4116f4
(anonymous) @ main.dart.mjs:836
setTimeout (async)
(anonymous) @ sender.ts:94
_send @ sender.ts:91
notifyServiceWorker @ indexed_db.ts:299
(anonymous) @ indexed_db.ts:356
await in (anonymous) (async)
_withPendingWrite @ indexed_db.ts:330
_remove @ indexed_db.ts:348
removeCurrentUser @ persistence_user_manager.ts:77
directlySetCurrentUser @ auth_impl.ts:790
initializeCurrentUser @ auth_impl.ts:293
await in initializeCurrentUser (async)
(anonymous) @ auth_impl.ts:181
IndexedDB (async)
getObject @ indexed_db.ts:145
(anonymous) @ indexed_db.ts:346
_withRetries @ indexed_db.ts:206
await in _withRetries (async)
_get @ indexed_db.ts:141
create @ persistence_user_manager.ts:145
IndexedDB (async)
_deleteObject @ indexed_db.ts:156
_isAvailable @ indexed_db.ts:318

Additional Information

Part of the WASM that fails

          local.get $var0
          block $label7 (result (ref $#Top))
            local.get $var5
            struct.get $<context file:///Users/hetzner/.pub-cache/hosted/pub.dev/firebase_auth_web-5.11.1/lib/src/interop/auth.dart:372:31> $field4
            call $JSAnyUtilityExtension|dartify
            br_on_non_null $label7
            call $StackTrace.current
            call $_TypeError._throwNullCheckError
            unreachable
          end $label7
          ref.cast $#Closure-0-0 <---- THIS IS THE FAILURE POINT
          local.tee $var10
          struct.get $#Closure-0-0 $field2
          local.get $var10
          struct.get $#Closure-0-0 $field3
          struct.get $#Vtable-0-0 $field1
          call_ref $type22866
          call $_awaitHelper
          ref.null none
          return

Flutter --version

This is our current version, and I also experienced the exact same issue using flutter main branch.

Flutter 3.22.0-23.0.pre.49 • channel [user-branch] • https://github.com/superlistapp/flutter.git
Framework • revision 36b6343df7 (9 days ago) • 2024-05-20 11:55:53 +0200
Engine • revision 900322f233
Tools • Dart 3.5.0 (build 3.5.0-131.0.dev) • DevTools 2.35.0

Dart info


If providing this information as part of reporting a bug, please review the information
below to ensure it only contains things you're comfortable posting publicly.

#### General info

- Dart 3.5.0-131.0.dev (dev) (Fri May 3 09:02:58 2024 -0700) on "macos_arm64"
- on macos / Version 14.5 (Build 23F79)
- locale is en-US

#### Project info

- sdk constraint: '>=3.0.0 <4.0.0'
- dependencies: android_content_provider, animate_do, animated_text_kit, animations, any_link_preview, app_settings, async, audioplayers, cached_network_image, characters, chopper, clock, collection, confetti, device_info_plus, diffutil_dart, diffutil_sliverlist, dio, drift, email_validator, emoji_picker_flutter, equatable, file_selector, firebase_analytics, firebase_auth, firebase_core, firebase_messaging, firebase_remote_config, flutter, flutter_cache_manager, flutter_downloader, flutter_localizations, flutter_staggered_grid_view, flutter_svg, flutter_web_plugins, follow_the_leader, freezed_annotation, gap, get_it, google_sign_in, google_sign_in_web, html, http, image_picker, image_picker_android, image_picker_platform_interface, in_app_review, intercom_flutter, intl, intl_utils, json_annotation, localizely_sdk, logging, meta, mime, package_info_plus, path, path_provider, protobuf, provider, pub_semver, quiver, retry, rive, rxdart, sentry_flutter, shared_preferences, sign_in_with_apple, sliver_tools, sqlite3_flutter_libs, stash, stash_memory, streaming_shared_preferences, super_clipboard, super_context_menu, super_drag_and_drop, super_hot_key, super_sliver_list, syncfusion_flutter_core, syncfusion_flutter_datepicker, timeago, timezone, transparent_image, tuple, ulid4d, universal_platform, url_launcher, uuid, vector_math, visibility_detector, web, web_socket_channel
- dev_dependencies: build_runner, chopper_generator, drift_dev, fake_async, fixnum, flutter_test, flutter_test_robots, freezed, integration_test, json_serializable, lint, mockito, path_provider_platform_interface, plugin_platform_interface, sentry_dart_plugin, swagger_dart_code_generator, test
- elided dependencies: 16

#### Process info

|  Memory |  CPU | Elapsed time | Command line                                                                               |
| ------: | ---: | -----------: | ------------------------------------------------------------------------------------------ |
|   53 MB | 0.0% |     01:37:34 | dart devtools --machine --dtd-uri=ws:<path>/5dzIkoPk7GZZNBPs                               |
|   54 MB | 0.0% |     01:37:34 | dart devtools --machine --dtd-uri=ws:<path>/XSFqO47sUbFjLb5M                               |
|   58 MB | 0.0% |     01:37:33 | dart devtools --machine --dtd-uri=ws:<path>/k3Sko8AoaWPRwXWL                               |
|   27 MB | 0.0% |     01:37:38 | dart devtools --machine --dtd-uri=ws:<path>/my5A4Dvwf5p5mMt2                               |
| 2783 MB | 0.0% |     01:37:47 | dart language-server --client-id=IntelliJ-IDEA --client-version=IU-241.15989.150 --protocol=analyzer |
|  322 MB | 0.0% |     01:37:34 | dart language-server --client-id=IntelliJ-IDEA --client-version=IU-241.15989.150 --protocol=analyzer |
|  366 MB | 0.0% |     01:37:34 | dart language-server --client-id=IntelliJ-IDEA --client-version=IU-241.15989.150 --protocol=analyzer |
|  447 MB | 0.0% |     01:37:33 | dart language-server --client-id=IntelliJ-IDEA --client-version=IU-241.15989.150 --protocol=analyzer |
|   29 MB | 0.0% |     01:37:38 | dart tooling-daemon --machine                                                              |
|   60 MB | 0.0% |     01:37:34 | dart tooling-daemon --machine                                                              |
|   61 MB | 0.0% |     01:37:34 | dart tooling-daemon --machine                                                              |
|   67 MB | 0.0% |     01:37:33 | dart tooling-daemon --machine                                                              |
eyebrowsoffire commented 5 months ago

This looks like a bug that was fixed in a subsequent version of on of the flutterfire packages (firebase_auth_web I think?). Can you update that package and tell me if this is still happening?

brian-superlist commented 5 months ago

Thanks, giving that a shot. My bad, I thought I'd done an upgrade on that package, but I was still behind by a couple of point version.

I'll report back.

brian-superlist commented 5 months ago

Looks like it's solved, I've now run into another issue with a different firebase library. Apologies for missing the update and thanks again for the help!

eyebrowsoffire commented 5 months ago

Just a heads up: there was also a compiler level issue with the firebase packages, and that fix hasn't yet made it into stable: https://github.com/dart-lang/sdk/issues/55457

But it should be fixed in flutter master, so it would be worth trying master if you're running into more firebase issues.

brian-superlist commented 5 months ago

Great, thanks again! We are running against very recent versions of Flutter since we contribute a lot of fixes that are important to our app, and I'd also tried the main as well.