[CLI] Avoid port conflicts when starting PHP-WASM network proxies - #3722
Merged
brandonpayton merged 7 commits intoJul 2, 2026
Merged
Conversation
This was referenced May 31, 2026
brandonpayton
approved these changes
Jul 2, 2026
brandonpayton
left a comment
Member
There was a problem hiding this comment.
Thanks for this fix, @chubes4! It makes sense, reads well, and tests well. Let's merge.
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.
What?
Binds php-wasm networking proxy servers directly on automatic ports (
0) and reads back assigned ports, instead of probing free ports first and rebinding concrete ports later.Why?
Fixes #3721.
The deeper root cause is in
@php-wasm/nodenetworking, not the top-level Playground CLI HTTP server:withNetworking()previously calledfindFreePorts(2).findFreePorts()opened temporarynet.Serverinstances on0, read their assigned ports, then closed them.127.0.0.1.addTCPServerToWebSocketServerClass().Tracing a downstream WP Codebox smoke test showed the relevant outbound sequence:
So the CLI was already passing
0correctly for its main server. The collision came from php-wasm choosing concrete “free” proxy ports before actually starting those proxies.How?
listenPort = 0.options.port = 0inside the server decorator.thisbinding.findFreePorts()helper and centralizes assigned-port lookup ingetServerPort().Testing
npx nx typecheck php-wasm-nodenpx vitest run packages/php-wasm/node/src/test/networking-port-allocation.spec.ts --config packages/php-wasm/node/vite.config.tsAI assistance