Fix php-wasm popen stream leaks#3679
Open
chubes4 wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR fixes file descriptor/stream leaks in the php-wasm popen() read-mode shim by switching to regular file closing semantics, and adds regression tests to ensure repeated process-output APIs don’t leak /tmp/popen_output streams.
Changes:
- Switch read-mode process-output streams from pipe-backed streams to file-backed streams (closing via
fclose()semantics). - Apply the same behavior to
exec()/shell_exec()/system()paths that consume the same shim. - Add a regression test that runs 100 iterations per API and asserts no increase in open
/tmp/popen_outputstreams (for PHP 8.3 builds).
Reviewed changes
Copilot reviewed 3 out of 7 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| packages/php-wasm/node/src/test/php-part-1.spec.ts | Adds regression coverage asserting no /tmp/popen_output stream leaks across repeated calls. |
| packages/php-wasm/compile/php/php_wasm.c | Switches wasm_php_exec stream creation from pipe semantics to file semantics. |
| packages/php-wasm/compile/php/Dockerfile | Patches upstream PHP sources so read-mode popen/exec use file semantics in wasm builds. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+623
to
+629
| const openPopenOutputCount = () => | ||
| (php as any)[__private__dont__use].FS.streams | ||
| .filter(Boolean) | ||
| .filter( | ||
| (stream: any) => | ||
| stream.path === '/tmp/popen_output' | ||
| ).length; |
9e77a00 to
f358f6e
Compare
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
popen()read-mode output with regular file-stream semantics because the shim buffers process output into/tmp/popen_output, not a real process pipe.php_exec()andshell_exec()paths that consume the same wasmpopen()shim.popen(),exec(),shell_exec(), andsystem()calls.Fixes #3678.
Testing
node packages/php-wasm/compile/build.js --PLATFORM=node --PHP_VERSION=8.3.31 --WITH_JSPI=yesnode packages/php-wasm/compile/build.js --PLATFORM=node --PHP_VERSION=8.3.30PHP=8.3 npm exec nx -- run php-wasm-node:test-group-1-jspi --testNamePattern=\"closes read-mode process output streams\"PHP=8.3 npm exec nx -- run php-wasm-node:test-group-1-asyncify --testNamePattern=\"closes read-mode process output streams\"npm exec nx -- run php-wasm-node:lintnpm exec nx -- run php-wasm-node:typecheckNotes
8_3_30, while JSPI points at8_3_31, so the rebuilt wasm artifacts preserve those existing paths.AI assistance