Skip to content

Fix php-wasm popen stream leaks - #3679

Open
chubes4 wants to merge 11 commits into
WordPress:trunkfrom
chubes4:fix/php-wasm-popen-stream-leak
Open

Fix php-wasm popen stream leaks#3679
chubes4 wants to merge 11 commits into
WordPress:trunkfrom
chubes4:fix/php-wasm-popen-stream-leak

Conversation

@chubes4

@chubes4 chubes4 commented May 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Close wasm popen() read-mode output with regular file-stream semantics because the shim buffers process output into /tmp/popen_output, not a real process pipe.
  • Apply the same close semantics to the php_exec() paths used by exec(), shell_exec(), system(), and passthru().
  • Add regression coverage for repeated process-output calls without leaked Emscripten FS streams.
  • Include focused PHP 8.3 Node.js JSPI and Asyncify builds used by the regression test.

Fixes #3678.

Testing

  • 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:test-group-1-jspi --testNamePattern="closes read-mode process output streams"
  • npm exec nx -- run php-wasm-node:lint
  • npm exec nx -- run php-wasm-node:typecheck
  • prettier --check packages/php-wasm/node/src/test/php-part-1.spec.ts packages/php-wasm/supported-php-versions.mjs

Artifact scope

  • PHP 8.3 Node.js Asyncify and JSPI artifacts are included so the regression test executes against the repaired runtime.
  • Other PHP versions and web artifacts remain unchanged; they will inherit the source fix when rebuilt.

AI assistance

  • OpenCode with OpenAI gpt-5.5 was used for initial root-cause analysis and patch/test drafting.
  • OpenCode with OpenAI gpt-5.6-sol was used to review the implementation, diagnose the GitHub diff timeout, narrow the generated artifact scope, and verify the repaired comparison. Chris reviewed and directed the work.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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_output streams (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 thread packages/php-wasm/node/src/test/php-part-1.spec.ts Outdated
Comment thread packages/php-wasm/node/src/test/php-part-1.spec.ts Outdated
Comment thread packages/php-wasm/compile/php/Dockerfile Outdated
chubes4 added 3 commits August 1, 2026 22:56
AI-assisted: gpt-5.6-terra via OpenCode diagnosed the Asyncify stream regression, implemented the cleanup correction, regenerated artifacts, and ran focused matrix tests.
AI assistance: OpenAI gpt-5.6-sol via OpenCode identified and removed formatter-only changes unrelated to the PHP-WASM fix.
@brandonpayton

Copy link
Copy Markdown
Member

Weird... GitHub is showing zero changes for this PR. I'm updating it to the latest from trunk to see whether it resets anything.

brandonpayton and others added 2 commits August 4, 2026 19:34
Remove unrelated all-version generated build refreshes while retaining the PHP 8.3 Node runtimes used by the regression test.

AI assistance: OpenAI gpt-5.6-sol via OpenCode diagnosed the GitHub diff timeout, narrowed the artifact scope, and verified the resulting base comparison. Chris reviewed and directed the work.
@brandonpayton

Copy link
Copy Markdown
Member

When I click the "Files Changed" tab, I've gotten different changed file counts this evening. I may just checkout the PR branch and review locally based on a Git diff.

@chubes4

chubes4 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

I think there was a glitch here, because I also saw no changes after your previous comment, then it was showing a large diff. After my last push it seems back to normal on my end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

php-wasm leaks popen output streams until FS.ErrnoError(33)

3 participants