Skip to content

fix(browser): prevent default entry detection and WS port conflicts#857

Merged
fi3ework merged 1 commit intomainfrom
conficport
Jan 9, 2026
Merged

fix(browser): prevent default entry detection and WS port conflicts#857
fi3ework merged 1 commit intomainfrom
conficport

Conversation

@fi3ework
Copy link
Copy Markdown
Member

@fi3ework fi3ework commented Jan 9, 2026

Summary

  • Use dynamic port allocation (port: 0) for WebSocket server instead of fixed container port + 1
  • Prevent EADDRINUSE error when the fixed port is already occupied
  • Add proper async handling with listening/error event awaiting

Related Links

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@netlify
Copy link
Copy Markdown

netlify bot commented Jan 9, 2026

Deploy Preview for rstest-dev ready!

Name Link
🔨 Latest commit b87d446
🔍 Latest deploy log https://app.netlify.com/projects/rstest-dev/deploys/6961322034d6c80008f551b1
😎 Deploy Preview https://deploy-preview-857--rstest-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

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

@fi3ework fi3ework marked this pull request as ready for review January 9, 2026 17:10
Copilot AI review requested due to automatic review settings January 9, 2026 17:10
@fi3ework fi3ework merged commit b5b4420 into main Jan 9, 2026
15 checks passed
@fi3ework fi3ework deleted the conficport branch January 9, 2026 17:10
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request addresses WebSocket server port conflicts by implementing dynamic port allocation. Instead of using a fixed port calculation (container port + 1), the WebSocket server now uses port: 0 to let the operating system assign an available port automatically, preventing EADDRINUSE errors when the calculated port is already in use.

Key changes:

  • Dynamic WebSocket port allocation using port: 0 instead of port + 1
  • Proper async handling with promise-based awaiting of 'listening'/'error' events
  • Added AddressInfo type import for proper type handling
Comments suppressed due to low confidence (1)

packages/browser/src/hostController.ts:1255

  • The value assigned to containerContext here is unused.
    containerContext = runtime.containerContext;

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

Comment on lines +1018 to +1022
await new Promise<void>((resolve, reject) => {
wss.once('listening', resolve);
wss.once('error', reject);
});
const wsPort = (wss.address() as AddressInfo).port;
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

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

If the WebSocket server fails to start (error event), the devServer won't be properly cleaned up. Consider wrapping this in a try-catch block and calling await devServer.close() before re-throwing the error, similar to how errors are handled in the subsequent try-catch blocks for playwright import and browser launch.

Suggested change
await new Promise<void>((resolve, reject) => {
wss.once('listening', resolve);
wss.once('error', reject);
});
const wsPort = (wss.address() as AddressInfo).port;
let wsPort: number;
try {
await new Promise<void>((resolve, reject) => {
wss.once('listening', resolve);
wss.once('error', reject);
});
wsPort = (wss.address() as AddressInfo).port;
} catch (_error) {
wss.close();
await devServer.close();
throw _error;
}

Copilot uses AI. Check for mistakes.
wss.once('listening', resolve);
wss.once('error', reject);
});
const wsPort = (wss.address() as AddressInfo).port;
Copy link

Copilot AI Jan 9, 2026

Choose a reason for hiding this comment

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

Although unlikely after the 'listening' event, wss.address() could potentially return null in edge cases. Consider adding a null check before accessing the port property to make the code more robust.

Suggested change
const wsPort = (wss.address() as AddressInfo).port;
const wsAddress = wss.address();
if (!wsAddress || typeof wsAddress === 'string') {
wss.close();
await devServer.close();
throw new Error('[Browser UI] Failed to determine WebSocket server address');
}
const wsPort = (wsAddress as AddressInfo).port;

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants