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

Fix: wasm panic catching errors and restoring application state and WebAssembly instance #4901

Merged
merged 13 commits into from
Jan 8, 2025

Conversation

nadr0
Copy link
Collaborator

@nadr0 nadr0 commented Jan 2, 2025

closes #4857

Issue

Rust can panic and we cannot try/catch the error in javascsript. Our JS internals brick because this.isExecuting is not set to false. Then the wasm instance from new WebAssembly bricks even more from our wbindgen.

Fix

  • Implemented global error handler to catch this specific global error because it will not be emitted in the try/catch block
  • Implemented error match to specifically switch case errors
  • Implemented a new reimport method for our wasm.ts and wasm-lib package.
  • When the error happens, I watch for it, then reload the module then re init the module with the default exported initialization function.

Technical bits

I posted several resource links in the original issue above

  • wbindgen has no way to re init the wasm instance, they have a conditional to block this
  • You cannot resize any WebAssembly memory after it has been initialized
  • You cannot overwrite any internals in the instance created from new WebAssembly
  • We have no access to wasm since it is a global variable within a file that has no export method

My only automatic way to detect this and fix it is by reimporting the file into memory and having a wrapper layer that points to that imported data. This means it won't point to the cache of the native import/export.

@nadr0 nadr0 linked an issue Jan 2, 2025 that may be closed by this pull request
Copy link

qa-wolf bot commented Jan 2, 2025

QA Wolf here! As you write new code it's important that your test coverage is keeping up.
Click here to request test coverage for this PR!

Copy link

vercel bot commented Jan 2, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
modeling-app ✅ Ready (Inspect) Visit Preview Jan 8, 2025 3:43pm

Copy link

codecov bot commented Jan 2, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.80%. Comparing base (65edf17) to head (4c30695).
Report is 20 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4901      +/-   ##
==========================================
- Coverage   85.82%   85.80%   -0.03%     
==========================================
  Files          86       87       +1     
  Lines       31005    31255     +250     
==========================================
+ Hits        26611    26817     +206     
- Misses       4394     4438      +44     
Flag Coverage Δ
wasm-lib 85.80% <ø> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/lib/wasm_lib_wrapper.ts Outdated Show resolved Hide resolved
src/lib/exceptions.ts Outdated Show resolved Hide resolved
@jessfraz jessfraz force-pushed the nadro/4857/wasm-panic-catching-errors branch from 7a28a52 to 636511a Compare January 7, 2025 20:34
@jessfraz jessfraz enabled auto-merge (squash) January 7, 2025 20:35
@nadr0 nadr0 changed the title Nadro/4857/wasm panic catching errors Fix: wasm panic catching errors and restoring application state and WebAssembly instance Jan 7, 2025
@jessfraz jessfraz merged commit 029f76f into main Jan 8, 2025
28 checks passed
@jessfraz jessfraz deleted the nadro/4857/wasm-panic-catching-errors branch January 8, 2025 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG]: WASM/Rust layer panics and cannot catch it.
3 participants