Skip to content

fix: atomically allocate standalone ws ports - #171

Merged
antfu merged 1 commit into
devframes:mainfrom
webfansplz:fix/atomic-ws-port-allocation
Aug 6, 2026
Merged

fix: atomically allocate standalone ws ports#171
antfu merged 1 commit into
devframes:mainfrom
webfansplz:fix/atomic-ws-port-allocation

Conversation

@webfansplz

@webfansplz webfansplz commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

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

  • default standalone WebSocket servers to an OS-assigned port
  • expose ready for awaiting server startup and listen errors
  • expose address() for retrieving the bound address and allocated port
  • make close() safe while the server is still starting
  • add coverage for concurrent transports receiving unique ports

Explicitly configured ports and shared HTTP/HTTPS servers continue to work as before.

Be related to vitejs/devtools#520

Copilot AI lite review requested due to automatic review settings August 6, 2026 03:24
@netlify

netlify Bot commented Aug 6, 2026

Copy link
Copy Markdown

Deploy Preview for devfra ready!

Name Link
🔨 Latest commit 40b6e91
🔍 Latest deploy log https://app.netlify.com/projects/devfra/deploys/6a73fe5d4373a50008def682
😎 Deploy Preview https://deploy-preview-171--devfra.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 ?? 0 via a listen() helper that surfaces bind/listen errors through a ready promise.
  • Expose ready (startup completion) and address() (bound address/port) on the returned WsRpcTransport.
  • 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()))
}
})

@antfu
antfu merged commit ec4ffb8 into devframes:main Aug 6, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants