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

Asyncify Crash in the Woocommerce onboarding flow #1078

Closed
adamziel opened this issue Mar 1, 2024 · 6 comments · Fixed by #1104
Closed

Asyncify Crash in the Woocommerce onboarding flow #1078

adamziel opened this issue Mar 1, 2024 · 6 comments · Fixed by #1104

Comments

@adamziel
Copy link
Collaborator

adamziel commented Mar 1, 2024

WP 6.4, PHP 8.0, networking enabled, no extra extensions. After installing the Woocommerce plugin, going through the Woo onboarding flow halts at one moment with a bunch of Asyncify errors. Let's identify where they come from and add the required functions to the ASYNCIFY_ALLOWLIST in the PHP build Dockerfile as well as thephp-asyncify.spec.ts unit tests

Here's a few ideas that would be good to test and Asyncify-allowlist regardless:

  • Generators
  • Stream wrappers
  • Shutdown handlers

To get nice stacktraces in the web version of PHP, it needs to be rebuilt with -O0 -g2 emcc flags here (hardcoding them for testing is fine):

@bgrgicak
Copy link
Collaborator

bgrgicak commented Mar 6, 2024

@bgrgicak
Copy link
Collaborator

bgrgicak commented Mar 6, 2024

I was able to recreate the issue locally. But after running npm run recompile:php:web:light:8.0 I can't recreate it anymore but not sure why.

@adamziel
Copy link
Collaborator Author

adamziel commented Mar 6, 2024

Weird @bgrgicak! Is there any chance it only happens in the kitchen sink bundle or with networking enabled? It could also be slightly non-deterministic, I remember successfully configuring woo in the past.

@bgrgicak
Copy link
Collaborator

bgrgicak commented Mar 7, 2024

I'm not sure why is this happening, but I had the same experience with PHP 8.1. I was able to recreate it until I rebuilt PHP. Then it stopped.

It also looks like these errors aren't producing crashes, Woo keeps running after the error, but it's slow.

@adamziel would you have some time to pair on this?

@adamziel
Copy link
Collaborator Author

adamziel commented Mar 7, 2024

@adamziel would you have some time to pair on this?

Sure, let's pair on Monday.

@adamziel
Copy link
Collaborator Author

I reproduced this issue with a PHP build that retains the function names, here's the stack trace I got:

base-php.ts:603 RuntimeError: null function or function signature mismatch
    at zend_objects_store_del (0164ced2:0xe801)
    at autoload_func_info_destroy (0164ced2:0x15262d)
    at autoload_func_info_zval_dtor (0164ced2:0x38a060)
    at zend_hash_destroy (0164ced2:0x897d)
    at zm_deactivate_spl (0164ced2:0x283eab)
    at dynCall_iii (0164ced2:0x3835d3)
    at ret.<computed> (php_8_0.js?t=1710169250590:6333:24)
    at runtime.asm.<computed> (wasm-error-reporting.ts:45:13)
    at invoke_iii (php_8_0.js?t=1710169250590:7125:10)
    at zend_deactivate_modules (0164ced2:0x314b72)
errorListener @ base-php.ts:603
runtime.asm.<computed> @ wasm-error-reporting.ts:60
invoke_iii @ php_8_0.js?t=1710169250590:7125
$zend_deactivate_modules @ 0164ced2:0x314b72
$dynCall_v @ 0164ced2:0x382f2a
ret.<computed> @ php_8_0.js?t=1710169250590:6333
runtime.asm.<computed> @ wasm-error-reporting.ts:45
invoke_v @ php_8_0.js?t=1710169250590:7224
$wasm_sapi_request_shutdown @ 0164ced2:0x3175f3
$dynCall_v @ 0164ced2:0x382f2a
ret.<computed> @ php_8_0.js?t=1710169250590:6333
runtime.asm.<computed> @ wasm-error-reporting.ts:45
invoke_v @ php_8_0.js?t=1710169250590:7224
$wasm_sapi_handle_request @ 0164ced2:0x31bfd2
ret.<computed> @ php_8_0.js?t=1710169250590:6333
runtime.asm.<computed> @ wasm-error-reporting.ts:45
ccall @ php_8_0.js?t=1710169250590:6524
exitCode @ base-php.ts:613
#handleRequest @ base-php.ts:600
run @ base-php.ts:278
error (async)
addEventListener @ wasm-error-reporting.ts:13
exitCode @ base-php.ts:609
#handleRequest @ base-php.ts:600
run @ base-php.ts:278
await in run (async)
#dispatchToPHP @ php-request-handler.ts:243
await in #dispatchToPHP (async)
request @ php-request-handler.ts:119
request @ php-browser.ts:61
request @ base-php.ts:234
request @ web-php-endpoint.ts:99
(anonymous) @ api.ts:169
callback @ comlink.ts:329

adamziel pushed a commit that referenced this issue Mar 13, 2024
Fixes #1078

## What is this PR doing?

If fixes an Asyncify error and memory leak when running PHP shutdown
functions.

## What problem is it solving?

It adds full support for PHP shutdown functions and prevents crashes.

## How is the problem addressed?

By adding Asyncify support for `wasm_sapi_request_shutdown` and
preventing `free` from running if memory wasn't allocated.

## Testing Instructions

- Checkout this branch
- Run dev env `npm run dev`
- [Open this
URL](http://localhost:5400/website-server/?php=8.0&wp=latest&storage=none&networking=yes#{%20%22landingPage%22:%20%22/wp-admin/%22,%20%22features%22:%20{%20%22networking%22:%20true%20},%20%22steps%22:%20[%20{%20%22step%22:%20%22login%22%20},%20{%20%22step%22:%20%22writeFile%22,%20%22path%22:%20%22/wordpress/wp-content/mu-plugins/rewrite.php%22,%20%22data%22:%20%22%3C?php%20add_action(%20'shutdown',%20function()%20{%20post_message_to_js('test');%20}%20);%22%20}%20]%20})
and confirm that WP loads without Asyncify errors and and memory leaks
(check the browser console)
@github-project-automation github-project-automation bot moved this from In progress to Done in Playground Board Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants