-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
If async preparing wasm fails, abort() to reject the module promise #12408
Conversation
Thanks for the PR @stephanreiter ! The first CI error appears to be that this succeeds when it should fail: err = self.run_js('a.out.js', assert_returncode=NON_ZERO) It does log the error message to the console, but looks like now the return code from the process is 0, which is not good. |
If this is just an issue on node, I wonder if |
One thought I've had, but am not sure about: in the MODULARIZE case there is a Promise the user can do a |
Maybe like this?
|
I just tested this for my use case and it does allow me to catch the error. 👍 Let me update the PR to see what CI tests think. |
@stephanreiter Yes, and looks like it passes tests! As I said I think that makes sense, but I'm not sure. The downside is adding a difference in MODULARIZE mode compared to normal mode. But, it does seem like the right thing to me..? If we do it, we'd need to add documentation and testing - in particular I doubt we have a test for MODULARIZE + failing to load the wasm, which we'd need. But first, it might be good to get more eyes on this, I'll cc some people that may have thoughts or ideas: @curiousdannii @lourd @RReverser (you can start reading from #12408 (comment) and/or just read the current code in the PR) |
For MODULARIZE I also believe this to be right. An instantiation failure will reject the module ready promise, and my app code will be informed that something went wrong (and also gets the details via the error object; this is actually better than going through abort() where the error is lost). |
@kripken I think this makes sense too. To be fair, personally I'd prefer never |
Thanks for taking a look! I added a test and rebased my PR. |
Need to fix how to report unhandled rejections from browser tests. |
We now have two tests of handling of module instantiation failure due to a) a global constructor performing an invalid memory access, and b) download failure. We check that the module promise is rejected and that no promise rejection remains unhandled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @stephanreiter ! Looks good to me with some test changes, + also please mention this in the Changelog.
Good changes, thanks @stephanreiter! LGTM. This looks similar to my PR #11625 that got reviewed and then fell along the wayside. @kripken, let me know if you'd like to see that one finished. I think the async control flow between instantiation, fallback instantiation, and receiving the instantiated module is still confusing. |
I think refactoring that code would be great, sure! |
…ady promise For example, if a global constructor performs an invalid memory access, an exception will be thrown that bubbles up to receiveInstantiatedSource. That causes a rejection of the promise returned from instantiateAsync, and we should forward that to the module consumer via the module ready promise. By handling that rejection we also avoid an unhandled-promise-rejection error in browsers. Fixes #12396
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!
For example, if a global constructor performs an invalid memory access,
an exception will be thrown that bubbles up to receiveInstantiatedSource.
That causes a rejection of the promise returned from instantiateAsync,
which we should handle.
Fixes #12396