Skip to content

Fix preview startup when the WebSocket port is occupied - #886

Closed
Mikhail Yaskou (mikhail-yaskou) wants to merge 1 commit into
microsoft:mainfrom
mikhail-yaskou:fix-websocket-port-collision
Closed

Mikhail Yaskou (mikhail-yaskou) wants to merge 1 commit into
microsoft:mainfrom
mikhail-yaskou:fix-websocket-port-collision

Conversation

@mikhail-yaskou

@mikhail-yaskou Mikhail Yaskou (mikhail-yaskou) commented Oct 30, 2026 •

Copy link
Copy Markdown

When the WebSocket port is occupied at startup, _handleWSError creates a replacement WSServerWithOriginCheck without registering its connection, error, or listening handlers. The replacement can bind successfully, but the original startup promise never settles, so ServerGrouping.openServer() never calls _connected() and Show Preview never opens. A second collision can also emit an unhandled error. The EADDRNOTAVAIL branch has the same missing handlers.

Restart through _startWSServer(basePath) in both recoverable error branches and chain its result to the original promise. Every bind attempt then registers the original handlers, and successful startup or failure propagates back to the caller.

Validation on Linux against the actual bundled _startWSServer method from Live Preview 0.4.20, using real TCP blockers and a real WebSocket client:

  • Original method, one held port: replacement bound at the next port, original promise remained pending, connection handler did not run.
  • Proposed method, two consecutive held ports: startup resolved and the connection handler ran at the third port.
  • Proposed method, unavailable starting host plus one held loopback port: reset to the default host, advanced past the blocker, resolved startup and handled the connection.

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.

1 participant