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

PHP: Ensures that ExitStatus error thrown by Emscripten has a stack trace attached #470

Merged
merged 1 commit into from
May 30, 2023

Conversation

adamziel
Copy link
Collaborator

Description

Overrides Emscripten's default ExitStatus object which gets thrown on failure. Unfortunately, the default object is not a subclass of Error and does not provide any stack trace.

This is a deliberate behavior on Emscripten's end to prevent memory leaks after the program exits. See:

emscripten-core/emscripten#9108

In case of WordPress Playground, the worker in which the PHP runs will typically exit after the PHP program finishes, so we don't have to worry about memory leaks.

As for assigning to a previously undeclared ExitStatus variable here, the Emscripten module declares ExitStatus as function ExitStatus which means it gets hoisted to the top of the scope and can be reassigned here – before the actual declaration is reached.

If that sounds weird, try this example:

ExitStatus = () => { console.log("reassigned"); }
function ExitStatus() {}
ExitStatus();
// logs "reassigned"

Testing instructions

Confirm the CI tests passed

Related: #416
cc @wojtekn

…race attached

Overrides Emscripten's default ExitStatus object which gets
thrown on failure. Unfortunately, the default object is not
a subclass of Error and does not provide any stack trace.

This is a deliberate behavior on Emscripten's end to prevent
memory leaks after the program exits. See:

emscripten-core/emscripten#9108

In case of WordPress Playground, the worker in which the PHP
runs will typically exit after the PHP program finishes, so
we don't have to worry about memory leaks.

As for assigning to a previously undeclared ExitStatus variable here,
the Emscripten module declares `ExitStatus` as `function ExitStatus`
which means it gets hoisted to the top of the scope and can be
reassigned here – before the actual declaration is reached.

If that sounds weird, try this example:

```js
ExitStatus = () => { console.log("reassigned"); }
function ExitStatus() {}
ExitStatus();
// logs "reassigned"
```
@adamziel adamziel added [Type] Bug An existing feature does not function as intended [Feature] PHP.wasm labels May 30, 2023
@adamziel adamziel self-assigned this May 30, 2023
@adamziel adamziel merged commit 01357b9 into trunk May 30, 2023
@adamziel adamziel deleted the ensure-ExitStatus-has-stack-trace branch May 30, 2023 10:18
@adamziel adamziel changed the title PHP: Ensures that ExitStatus error thrown my Emscripten has a stack trace attached PHP: Ensures that ExitStatus error thrown by Emscripten has a stack trace attached May 30, 2023
@wojtekn
Copy link
Collaborator

wojtekn commented May 30, 2023

Thanks @adamziel . I've tested it on my crashing instance, and now it shows the stack trace.

I also noticed that now it doesn't log the exit message from PHP, which was zend_mm_heap corrupted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] PHP.wasm [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants