Skip to content

[dotnet-watch] Clear WebSocket env vars in ClearHotReloadEnvironmentVariables#53999

Merged
jonathanpeppers merged 1 commit intodotnet:release/10.0.4xxfrom
jonathanpeppers:dotnet-watch-web-socket-fix
Apr 21, 2026
Merged

[dotnet-watch] Clear WebSocket env vars in ClearHotReloadEnvironmentVariables#53999
jonathanpeppers merged 1 commit intodotnet:release/10.0.4xxfrom
jonathanpeppers:dotnet-watch-web-socket-fix

Conversation

@jonathanpeppers
Copy link
Copy Markdown
Member

I just noticed this reading the code -- not sure if it actually causes a problem, but should probably be fixed.

ClearHotReloadEnvironmentVariables already clears the named pipe env var ($DOTNET_WATCH_HOTRELOAD_NAMEDPIPE_NAME) but does not clear the WebSocket equivalents ($DOTNET_WATCH_HOTRELOAD_WEBSOCKET_ENDPOINT and $DOTNET_WATCH_HOTRELOAD_WEBSOCKET_KEY). Fix parity so WebSocket env vars are also cleared for child processes.

Copilot AI review requested due to automatic review settings April 20, 2026 16:20
@jonathanpeppers jonathanpeppers requested review from a team and tmat as code owners April 20, 2026 16:20
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 PR updates dotnet-watch hot reload startup-hook behavior to fully clear transport-specific environment variables so they don’t leak into child processes (named pipe and WebSocket parity).

Changes:

  • Clear DOTNET_WATCH_HOTRELOAD_WEBSOCKET_ENDPOINT in ClearHotReloadEnvironmentVariables.
  • Clear DOTNET_WATCH_HOTRELOAD_WEBSOCKET_KEY in ClearHotReloadEnvironmentVariables.

Comment on lines 307 to 310
Environment.SetEnvironmentVariable(AgentEnvironmentVariables.DotNetWatchHotReloadNamedPipeName, null);
Environment.SetEnvironmentVariable(AgentEnvironmentVariables.DotNetWatchHotReloadWebSocketEndpoint, null);
Environment.SetEnvironmentVariable(AgentEnvironmentVariables.DotNetWatchHotReloadWebSocketKey, null);
Environment.SetEnvironmentVariable(AgentEnvironmentVariables.HotReloadDeltaClientLogMessages, null);
Copy link

Copilot AI Apr 20, 2026

Choose a reason for hiding this comment

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

Add/extend a unit test to cover the new behavior: when DOTNET_WATCH_HOTRELOAD_WEBSOCKET_ENDPOINT / DOTNET_WATCH_HOTRELOAD_WEBSOCKET_KEY are set, ClearHotReloadEnvironmentVariables should clear them (and restore originals in a finally to avoid test cross-contamination).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The existing env var clearing (named pipe, log messages) also has no test verifying they're unset.

ClearHotReloadEnvironmentVariables already clears the named pipe env
var (DOTNET_WATCH_HOTRELOAD_NAMEDPIPE_NAME) but does not clear the
WebSocket equivalents (DOTNET_WATCH_HOTRELOAD_WEBSOCKET_ENDPOINT and
DOTNET_WATCH_HOTRELOAD_WEBSOCKET_KEY). Fix parity so WebSocket env
vars are also cleared for child processes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@marcpopMSFT marcpopMSFT force-pushed the dotnet-watch-web-socket-fix branch from 061374b to 25a6e70 Compare April 20, 2026 22:07
@marcpopMSFT
Copy link
Copy Markdown
Member

rebasing with the branch now that #53993 is merged.

@jonathanpeppers jonathanpeppers merged commit dc458ab into dotnet:release/10.0.4xx Apr 21, 2026
28 checks passed
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.

4 participants