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: Process crash when intentionally triggering Asyncify error on 5.6, 7.2, 8.2 #353

Closed
adamziel opened this issue May 16, 2023 · 1 comment
Labels
[Feature] PHP.wasm [Type] Bug An existing feature does not function as intended [Type] Developer Experience

Comments

@adamziel
Copy link
Collaborator

The test below crashes the process with Bus Error message on PHP 5.6, 7.2, and 8.2.

Asyncify errors are not meant to happen, but that crash will make debugging tedious when they do happen.

// @TODO Prevent crash on PHP versions 5.6, 7.2, 8.2
describe.each(['7.0','7.1','7.3','7.4','8.0','8.1'])('PHP %s – process crash', (phpVersion) => {
	let php: NodePHP;
	beforeEach(async () => {
		php = await NodePHP.load(phpVersion as any);
		php.setPhpIniEntry('allow_url_fopen', '1');
	});

	it('Does not crash due to an unhandled Asyncify error ', async () => {
		let caughtError;
		try {
			/**
			 * PHP is intentionally built without network support for __clone()
			 * so we can test the error handling here.
			 *
			 * `clone $x` will throw an asynchronous error out when attempting
			 * to do a network call ("unreachable" WASM instruction executed).
			 * This test should gracefully catch and handle that error.
			 *
			 * A failure to do so will crash the entire process
			 */
			await php.run({
				code: `<?php
				class Top {
					function __clone() {
						file_get_contents("http://127.0.0.1");
					}
				}
				$x = new Top();
				clone $x;
				`,
			});
		} catch (error) {
			caughtError = error;
			expect(error).toMatch(/Aborted|Program terminated with exit\(1\)|/);
		}
		if (!caughtError) {
			expect.fail('php.run should have thrown an error');
		}
	});
});
@adamziel adamziel added [Type] Bug An existing feature does not function as intended [Feature] PHP.wasm [Type] Developer Experience labels May 16, 2023
@adamziel
Copy link
Collaborator Author

Duplicate: doubly submitted with #354

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 [Type] Developer Experience
Projects
None yet
Development

No branches or pull requests

1 participant