Skip to content

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

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

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
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.

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

2 participants