fix: atomically allocate standalone ws ports - #171
Merged
Conversation
✅ Deploy Preview for devfra ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
webfansplz
marked this pull request as draft
August 6, 2026 03:24
webfansplz
marked this pull request as ready for review
August 6, 2026 03:26
There was a problem hiding this comment.
Pull request overview
Updates the devframe WebSocket RPC transport so standalone servers bind to OS-assigned ports (port 0) to avoid race conditions from “probe then bind” port allocation, and exposes readiness/address APIs to support awaiting startup and discovering the allocated port.
Changes:
- Default standalone WS transport binding to
port ?? 0via alisten()helper that surfaces bind/listen errors through areadypromise. - Expose
ready(startup completion) andaddress()(bound address/port) on the returnedWsRpcTransport. - Add a concurrency-oriented test ensuring multiple standalone transports receive unique, non-zero ports.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/devframe/src/rpc/transports/ws-server.ts | Adds ready/address() to the WS transport and switches standalone servers to atomic OS-assigned port allocation (port 0) with safer startup/teardown handling. |
| packages/devframe/src/rpc/transports/ws.test.ts | Adds coverage asserting concurrent standalone transports allocate unique OS-chosen ports and can report them via address(). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| await Promise.all(transports.map(transport => transport.close())) | ||
| } | ||
| }) | ||
|
|
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.
Standalone WebSocket transports previously relied on callers to find an available port before starting the server. Because probing and binding happened separately, concurrent processes could select the same port and fail with
EADDRINUSE.Default standalone transports now listen on port
0, allowing the operating system to select and reserve an available port atomically.Changes
readyfor awaiting server startup and listen errorsaddress()for retrieving the bound address and allocated portclose()safe while the server is still startingExplicitly configured ports and shared HTTP/HTTPS servers continue to work as before.
Be related to vitejs/devtools#520