Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion MCPForUnity/Editor/Services/StdioBridgeReloadHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ private static void OnBeforeAssemblyReload()
// Stop only stdio before reload. This is centralized here so resume-flag updates
// and teardown cannot race each other via separate beforeAssemblyReload handlers.
var stopTask = MCPServiceLocator.TransportManager.StopAsync(TransportMode.Stdio);
try { stopTask.Wait(500); } catch { }
// Match StdioBridgeHost.Stop's 2s socket-release wait; 500ms is too short on
// Windows and lets the next reload bind the same port before the OS frees it.
try { stopTask.Wait(2000); } catch { }
Comment on lines 72 to +75

// Legacy safety: stdio may have been started outside TransportManager state.
try { StdioBridgeHost.Stop(); } catch { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,10 @@ public static void Stop()

if (toWait != null)
{
// CTS is already cancelled; give the listener task a brief moment to exit.
try { toWait.Wait(500); } catch { }
// Windows needs the full 2s for the socket to release after Dispose; with 500ms
// the next Start() can hit AddressAlreadyInUse and silently fall back to a new
// port, orphaning the listener. See #1173 / #688.
try { toWait.Wait(2000); } catch { }
}
Comment on lines +399 to 403

// ProcessCommands stays permanently hooked (guarded by _processCommandsHooked)
Expand Down
Loading