Skip to content

fix(core): allocate standalone WebSocket ports atomically - #520

Closed
webfansplz wants to merge 3 commits into
mainfrom
fix/race-safe-ws-port-allocation
Closed

fix(core): allocate standalone WebSocket ports atomically#520
webfansplz wants to merge 3 commits into
mainfrom
fix/race-safe-ws-port-allocation

Conversation

@webfansplz

Copy link
Copy Markdown
Member

Vite DevTools previously selected a standalone WebSocket port with get-port-please before starting the server. Concurrent processes could probe the same available port and then race to bind it, causing all but one to fail with EADDRINUSE.

Default port allocation is now delegated to the Devframe transport, which binds to port 0 and lets the operating system select and reserve an available port atomically.

Changes

  • remove the probe-before-bind port allocation from the standalone WebSocket path
  • wait for the Devframe transport to start listening
  • retrieve the actual bound port from the transport
  • publish the WebSocket endpoint and refresh remote docks after the port is resolved
  • preserve explicitly configured ports
  • keep the shared Vite HTTP server path unchanged

Standalone environments that require a stable port can continue to configure websocket.port explicitly.

Waitting for devframes/devframe#171, Fix #517

Copilot AI lite review requested due to automatic review settings August 6, 2026 03:26
@webfansplz
webfansplz marked this pull request as draft August 6, 2026 03:26
@pkg-pr-new

pkg-pr-new Bot commented Aug 6, 2026

Copy link
Copy Markdown

Open in StackBlitz

@vitejs/devtools

npm i https://pkg.pr.new/@vitejs/devtools@520

@vitejs/devtools-kit

npm i https://pkg.pr.new/@vitejs/devtools-kit@520

@vitejs/devtools-oxc

npm i https://pkg.pr.new/@vitejs/devtools-oxc@520

@vitejs/devtools-rolldown

npm i https://pkg.pr.new/@vitejs/devtools-rolldown@520

@vitejs/devtools-vite

npm i https://pkg.pr.new/@vitejs/devtools-vite@520

@vitejs/devtools-vitest

npm i https://pkg.pr.new/@vitejs/devtools-vitest@520

commit: fbde652

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

This PR fixes a race condition in standalone WebSocket port selection for Vite DevTools by removing probe-before-bind logic and relying on the underlying Devframe WS transport to bind atomically (port 0 → OS-assigned port), then publishing the resolved endpoint for remote docks.

Changes:

  • Remove get-port-please pre-allocation and delegate default standalone port selection to the Devframe transport.
  • Await transport readiness and read back the actual bound port from transport.address().
  • Publish the resolved WS endpoint and re-emit remote dock update events once the endpoint is known.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/core/src/node/ws.ts
Comment thread packages/core/src/node/ws.ts Outdated
@webfansplz
webfansplz force-pushed the fix/race-safe-ws-port-allocation branch from f054ea3 to 932e70b Compare August 6, 2026 04:35
@webfansplz
webfansplz marked this pull request as ready for review August 6, 2026 04:37
@antfubot

Copy link
Copy Markdown
Collaborator

Thanks for this fix!

As of #529, the standalone WebSocket server previously at packages/core/src/node/ws.ts has moved out of this repo — the WS transport (and the port-binding logic this PR touches) is now owned upstream by devframe's WsRpcTransport/initHub, and this repo consumes it as a published dependency.

Good news: the atomic-port-binding half of this fix already shipped there — devframes/devframe#171 (merged) binds standalone transports to port 0 and lets the OS pick atomically, and it's already included in the devframe@0.9.0-beta.2 this repo now depends on, so #517's EADDRINUSE race is resolved. We're labeling this devframe and opened devframes/devframe#206 to verify/port the other half — publishing the resolved WS endpoint and refreshing remote docks once binding completes — since that responsibility also moved upstream.

Thank you for tracking down #517 and flagging the upstream dependency yourself — we're crediting you as the original author on the linked issue. Closing this one in spirit since the bulk of the fix already landed; follow devframes/devframe#206 for the remainder.

@antfubot antfubot added the devframe Affected by the devframe/hub-ui migration; fix belongs upstream in devframe label Aug 14, 2026
@webfansplz webfansplz closed this Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

devframe Affected by the devframe/hub-ui migration; fix belongs upstream in devframe

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DevTools opens a fixed-port (7812) WS server under Vitest, parallel monorepo test runs crash with EADDRINUSE

3 participants