forked from WordPress/playground-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
npm run fix-asyncify
task that adds the missing ASYNCIFY_ONLY i…
…tems (WordPress#253) With this commit, fixing Asyncify issues only requires: 1. Adding a test case that triggers a crash to `packages/php-wasm/node/src/test/php-asyncify.spec.ts` 2. Running: ```bash npm run fix-asyncify ``` The fix-asyncify command: 1. Runs Asyncify test suite that makes PHP trigger an async call through all known code paths. If it works, we're done. If it fails, keep going. 2. Automatically adds any missing C functions to the ASYNCIFY_ONLY list in the Dockerfile 3. Rebuilds PHP 4. Loops to 1 To make it work, this PR: * Converts unhandled Asyncify rejections into catchable errors thrown inside `PHP.run()` * Logs PHP functions at the time of an async call, not at the time of rewinding * Prevents Node.js from exiting or hiding the error message when the WASM module calls exit() ## Follow-up work * Add a documentation page cc @sejas @danielbachhuber
- Loading branch information
Showing
47 changed files
with
913 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
packages/php-wasm/compile/build-assets/append-before-return.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/** | ||
* Debugging Asyncify errors is tricky because the stack trace is lost when the | ||
* error is thrown. This code saves the stack trace in a global variable | ||
* so that it can be inspected later. | ||
*/ | ||
PHPLoader.debug = 'debug' in PHPLoader ? PHPLoader.debug : true; | ||
if (PHPLoader.debug) { | ||
const originalHandleSleep = Asyncify.handleSleep; | ||
Asyncify.handleSleep = function (startAsync) { | ||
if (!ABORT) { | ||
Module["lastAsyncifyStackSource"] = new Error(); | ||
} | ||
return originalHandleSleep(startAsync); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
packages/php-wasm/node/bin/rebuild-while-asyncify-functions-missing.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { execSync, spawnSync } from 'child_process'; | ||
import { createHash } from 'crypto'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { hash } from 'ts-json-schema-generator'; | ||
import { phpVersions } from '../../supported-php-versions.mjs'; | ||
|
||
const PHP_VERSIONS = process.env.PHP | ||
? [process.env.PHP] | ||
: phpVersions.map(({ version }) => version); | ||
let hash1 = ''; | ||
let hash2 = ''; | ||
for (const PHP_VERSION of PHP_VERSIONS) { | ||
while (true) { | ||
console.log(`Running asyncify tests for PHP ${PHP_VERSION}...`); | ||
hash1 = getHash(); | ||
// Need to reset nx server/cache or otherwise | ||
// all the test runs will come from cache. | ||
spawnSync('node', ['./node_modules/.bin/nx', 'reset']); | ||
spawnSync( | ||
'node', | ||
[ | ||
'--stack-trace-limit=100', | ||
'./node_modules/.bin/nx', | ||
'test', | ||
'php-wasm-node', | ||
'--test-name-pattern=asyncify', | ||
], | ||
{ | ||
env: { | ||
...process.env, | ||
PHP: PHP_VERSION, | ||
FIX_DOCKERFILE: 'true', | ||
}, | ||
} | ||
); | ||
|
||
hash2 = getHash(); | ||
if (hash1 === hash2) { | ||
console.log(`Dockerfile did not change!`); | ||
break; | ||
} | ||
|
||
console.log(`Dockerfile changed, recompiling PHP...`); | ||
spawnSync('npm', ['run', `recompile:php:node:${PHP_VERSION}`]); | ||
} | ||
} | ||
|
||
function getHash() { | ||
return createHash('sha1') | ||
.update( | ||
fs.readFileSync( | ||
new URL('../../compile/Dockerfile', import.meta.url).pathname | ||
) | ||
) | ||
.digest('hex'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,7 +91,7 @@ | |
"minify": false | ||
}, | ||
"production": { | ||
"minify": true | ||
"minify": false | ||
} | ||
} | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Oops, something went wrong.