Repository navigation
Launch the local HTTP server without inheriting the editor's handles - #51
Merged
Merged
Conversation
On Windows, Mono's Process.Start calls CreateProcessW with bInheritHandles hard-coded TRUE, so the server's launch process (cmd, then uvx, uv and python) got a copy of every inheritable handle the editor held, including its open Logs/Editor.log. The server outlives the editor, so that log stayed locked and every later editor of the project fell back to the machine-global Editor.log (#50). ServerProcessLauncher makes the CreateProcessW call Mono makes with inheritance off: same command line and environment block, created suspended so Process.GetProcessById gets its handle before the process can exit, with that handle made non-inheritable as Process.Start's is. It passes no std handles, so cmd uses its own hidden console's. Unsupported ProcessStartInfo fields throw NotSupportedException on every platform; off Windows it is Process.Start (Mono closes descriptors above 2 in a POSIX child). Tests: the launched process holds no copy of an inheritable editor handle (red on Process.Start), the returned handle is not inheritable (red without the SetHandleInformation call), the launch matches Process.Start's environment and working directory, and the contract rejects unsupported fields. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018mVoikeBS5RijnEmvTr8RR
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018mVoikeBS5RijnEmvTr8RR
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
On Windows, the local HTTP server started from an editor kept that editor's
Logs/Editor.loglocked for the server's whole life. Every later editor of the project then fell back to the machine-globalEditor.log(#50).The cause is Mono's
Process.Start: it callsCreateProcessWwithbInheritHandleshard-codedTRUE. So the launch process (cmd, thenuvx,uvandpython) got a copy of every inheritable handle the editor held, including its open log.The server launch now goes through
ServerProcessLauncher, which makes the sameCreateProcessWcall with inheritance off.Fixes #50
Type of Change
Changes Made
MCPForUnity/Editor/Services/Server/ServerProcessLauncher.cs, which on Windows makes Mono'sCreateProcessWcall with these differences:bInheritHandles = FALSE.cmduses its own hidden console's.Process.GetProcessByIdgets its handle before the process can exit. That handle is then made non-inheritable, asProcess.Start's is.EnvironmentVariablesin the same order.Process.Start: Mono closes descriptors above 2 in a POSIX child, so nothing leaks there.UseShellExecute, redirects,UserNameandArgumentListthrowNotSupportedExceptioninstead of being silently dropped.ServerManagementService.StartLocalHttpServer: a one-line change to call the launcher.ServerProcessLauncherTests(Windows cases useAssert.Ignoreelsewhere):Process.Start.SetHandleInformationcall.cd & setoutput is identical toProcess.Start's: working directory and environment.NotSupportedException.10.2.0-fork.2.Behaviour changes (Windows)
cmd's own messages go to its hidden console, not to the editor's std handles, which a GUI editor does not have. The server's output still goes to the launch log through the existing< NUL >> log 2>&1.EnvironmentVariableswas never touched now passes a snapshot of the editor's environment, without Windows' hidden=C:drive entries. The production launch always touches it (the uvPATHprepend), so only the characterization fake (cmd /c exit) takes this path.Compatibility / Package Source
file:(TestProjects/UnityMCPTests)Testing
python tools/local_harness.py --legs editmodegave 1035/1114 passed, 0 failed.ServerProcessLauncherTests,ServerManagementServiceCharacterizationTestsandTerminalLauncherTests: 72/72 passed.Server/is untouched.Related Issues
Fixes #50
Additional Notes
com.unity.ide.visualstudio) can still hold the log the same way. That launch is outside this package.🤖 Generated with Claude Code
https://claude.ai/code/session_018mVoikeBS5RijnEmvTr8RR