Add separate WS and WSS ports for browser refresh server to fix TLS port conflict#52959
Add separate WS and WSS ports for browser refresh server to fix TLS port conflict#52959
Conversation
When DOTNET_WATCH_AUTO_RELOAD_WS_PORT is set and TLS dev certificates are available, BrowserRefreshServer was trying to bind both HTTP and HTTPS to the same port, which causes an "address already in use" error. Fixed by only binding HTTPS when TLS is supported, instead of both HTTP and HTTPS to the same port. This is the correct behavior since you cannot bind both protocols to the same TCP port. Co-authored-by: dbreshears <3432571+dbreshears@users.noreply.github.com>
|
@copilot, please revert the last change, what is needed is 2 Environment variables. DOTNET_WATCH_AUTO_RELOAD_WS_PORT and a new one DOTNET_WATCH_AUTO_RELOAD_WSS_PORT with variables for AutoReloadWSPort and AutoReloadWSSPort. Then in FromEnvironment we need AutoReloadWebSocketSecurePort set to AutoReloadWSSPort |
- Added DOTNET_WATCH_AUTO_RELOAD_WSS_PORT environment variable - Added AutoReloadWebSocketSecurePort property to EnvironmentOptions - Updated BrowserRefreshServer to use separate ports for HTTP and HTTPS - This allows users to avoid port conflicts when TLS is supported When TLS is available, users can now set: - DOTNET_WATCH_AUTO_RELOAD_WS_PORT for HTTP (e.g., 8081) - DOTNET_WATCH_AUTO_RELOAD_WSS_PORT for HTTPS (e.g., 8082) Co-authored-by: dbreshears <3432571+dbreshears@users.noreply.github.com>
Done! I've implemented the two environment variables approach:
Users can now set: export DOTNET_WATCH_AUTO_RELOAD_WS_PORT=8081
export DOTNET_WATCH_AUTO_RELOAD_WSS_PORT=8082
dotnet watchTested and verified both ports are used correctly. Commit: 813585f |
Renamed properties and variables as requested: - AutoReloadWebSocketHostName → BrowserWebSocketHostName - AutoReloadWebSocketPort → BrowserWebSocketPort - AutoReloadWebSocketSecurePort → BrowserWebSocketSecurePort Updated in: - EnvironmentOptions.cs (property definitions and FromEnvironment) - BrowserRefreshServer.cs (constructor parameters and local variables) - WebApplicationAppModel.cs (property usage) Co-authored-by: tmat <41759+tmat@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR fixes a port binding conflict in dotnet watch when DOTNET_WATCH_AUTO_RELOAD_WS_PORT is set with TLS support enabled. Previously, the browser refresh server attempted to bind both HTTP and HTTPS endpoints to the same port, causing an "address already in use" error. The fix introduces a new environment variable DOTNET_WATCH_AUTO_RELOAD_WSS_PORT to allow separate configuration of WebSocket ports for HTTP and HTTPS connections.
Changes:
- Adds
DOTNET_WATCH_AUTO_RELOAD_WSS_PORTenvironment variable for HTTPS WebSocket port configuration - Renames internal properties from
AutoReloadWebSocket*toBrowserWebSocket*for better clarity - Updates browser refresh server to use separate ports for HTTP and HTTPS when TLS is supported
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/BuiltInTools/Watch/Context/EnvironmentVariables.cs | Adds AutoReloadWSSPort property to read the new HTTPS port environment variable |
| src/BuiltInTools/Watch/Context/EnvironmentOptions.cs | Renames WebSocket-related properties and adds BrowserWebSocketSecurePort property |
| src/BuiltInTools/Watch/AppModels/WebApplicationAppModel.cs | Updates parameter names and passes the new secure port to BrowserRefreshServer |
| src/BuiltInTools/HotReloadClient/Web/BrowserRefreshServer.cs | Accepts secure port parameter and uses it for HTTPS endpoint binding |
| browserWebSocketHostName: context.EnvironmentOptions.BrowserWebSocketHostName, | ||
| browserWebSocketPort: context.EnvironmentOptions.BrowserWebSocketPort, | ||
| browserWebSocketSecurePort: context.EnvironmentOptions.BrowserWebSocketSecurePort, |
There was a problem hiding this comment.
This change introduces a new environment variable and modifies the browser refresh server's port binding behavior, but there are no new tests to verify this functionality. Consider adding a test that verifies when both DOTNET_WATCH_AUTO_RELOAD_WS_PORT and DOTNET_WATCH_AUTO_RELOAD_WSS_PORT are set with TLS enabled, the HTTP and HTTPS endpoints bind to their respective ports correctly.
|
Superseded by #53108 |
Fix dotnet watch port binding when DOTNET_WATCH_AUTO_RELOAD_WS_PORT is set with TLS
Changes:
DOTNET_WATCH_AUTO_RELOAD_WSS_PORTBrowserWebSocketSecurePortproperty to EnvironmentOptionsOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.