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 shutdown errors #1104

Merged
merged 9 commits into from
Mar 13, 2024
Merged

Fix shutdown errors #1104

merged 9 commits into from
Mar 13, 2024

Conversation

bgrgicak
Copy link
Collaborator

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 and confirm that WP loads without Asyncify errors and and memory leaks (check the browser console)

@bgrgicak bgrgicak self-assigned this Mar 13, 2024
@bgrgicak bgrgicak requested a review from adamziel March 13, 2024 08:50
@bgrgicak
Copy link
Collaborator Author

@adamziel I tried adding tests, but wasn't able to crash it using PHP shutdown functions.
Could this be because test use the node version?

@bgrgicak bgrgicak added [Type] Bug An existing feature does not function as intended [Feature] PHP.wasm [Aspect] Asyncify labels Mar 13, 2024
@adamziel
Copy link
Collaborator

adamziel commented Mar 13, 2024

@adamziel I tried adding tests, but wasn't able to crash it using PHP shutdown functions. Could this be because test use the node version?

Snap! I ran into the same issue. It sounds like only the web version crashes at the intersection of Asyncify and shutdown handlers which is weird. Well, let's at least add an e2e test for the web to confirm that Blueprint works on all PHP versions with and without the kitchen sink bundle. Also, it seems like this PR only rebuilds the kitchen sink bundle >= 8.1?

@bgrgicak
Copy link
Collaborator Author

Also, it seems like this PR only rebuilds the kitchen sink bundle >= 8.1?

Everything should be rebuilt now (66b0c97). I had some issues with the rebuild script and Docker, so I had to do it in three stages (light, kitchen-sink, node).

@bgrgicak bgrgicak force-pushed the fix/1078-woo-asyncify-crash branch from 3f07c6e to 005dc24 Compare March 13, 2024 09:28
Comment on lines +30 to +36
let envelope: RequestMessage;
try {
// PHP-WASM sends messages as strings, so we can't expect valid JSON.
envelope = JSON.parse(message);
} catch (e) {
return '';
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamziel I ended up wrapping this in a try/catch. If we expect json, we shouldn't throw an error.
If there is a plain text message, it's not intended for this code.

@bgrgicak
Copy link
Collaborator Author

Well, let's at least add an e2e test for the web to confirm that Blueprint works on all PHP versions with and without the kitchen sink bundle.

Done 005dc24. I also confirmed it fails on trunk.

@@ -81,4 +81,21 @@ describe('Blueprints', () => {
.find('[aria-label="“Test post” (Edit)"]')
.should('exist');
});

it('PHP Shutdown should work', () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: In a follow-up PR let's add a comment to link this test to this PR and the associated issue in case anyone would wonder where did this test come from.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do that. Wouldn't git blame be enough here? This is at least how I would search for it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be enough until the first time this file is reformatted or until the test is refactored or moved to another file. WordPress core also documents all tests with ticket numbers, I was sceptical at first but then I found it actually helpful over time.

@adamziel adamziel merged commit 30466b1 into trunk Mar 13, 2024
5 checks passed
@adamziel adamziel deleted the fix/1078-woo-asyncify-crash branch March 13, 2024 13:21
@adamziel adamziel mentioned this pull request Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Aspect] Asyncify [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.

Asyncify Crash in the Woocommerce onboarding flow
2 participants