Skip to content

StdioBridgeHost enters zombie state after Python server restart — accepts connections but never processes commands #785

@dsarno

Description

@dsarno

Summary

When the Python MCP server process restarts (e.g., via /mcp reconnect in Claude Code), Unity's StdioBridgeHost socket listener enters a zombie state — it accepts new TCP connections on port 6404 but never processes the incoming command data. The Unity Editor UI appears completely normal ("Session Active", green dot), and the server successfully connects and sends data, but Unity never responds.

Restarting the session from the Unity side (End Session + Start Session) immediately fixes the issue.

Reproduction Steps

  1. Open a Unity project with MCP for Unity running (stdio transport, port 6404)
  2. Connect from Claude Code — verify tool calls work
  3. Run /mcp in Claude Code to reconnect (this kills and restarts the Python server process)
  4. Immediately make tool calls — they all timeout

Observed Behavior

  • Server discovers Unity on port 6404 (correct)
  • TCP connections succeed (connect took 0.002s)
  • Data sends succeed (sendall took 0.000s)
  • Unity never responds — every command hits the 1-second socket timeout
  • All 6 retry attempts fail for every command
  • This persists indefinitely (tested for several minutes)
  • Unity Editor UI shows "Session Active" with green dot, no errors in Console

Server Logs

14:10:29 [INFO]  send_command_with_retry START command=get_project_info
14:10:29 [INFO]  Discovered 1 Unity instances
14:10:29 [INFO]  connect took 0.001s command=get_project_info
14:10:29 [INFO]  sendall took 0.000s command=get_project_info
14:10:59 [WARN]  Socket timeout during framed receive
14:10:59 [WARN]  Unity communication attempt 1 failed: Timeout receiving Unity response
... (repeats through attempt 6, every command)

Key detail: the first timeout on get_project_info takes 30 seconds (14:10:29 → 14:10:59), suggesting a longer initial timeout. Subsequent retries timeout at 1 second each.

Expected Behavior

When the Python server restarts and opens new TCP connections to the same port, Unity should process commands from the new connections normally.

Root Cause Hypothesis

When the old Python server process dies, its TCP connections to Unity's socket listener are severed. The StdioBridgeHost may not properly clean up the old connection state, so when new connections arrive on the same port, the accept/read loop is stuck or blocked on the stale connection. The socket is listening (connections succeed) but the command dispatcher never reads from the new connections.

Resolution

End Session + Start Session in the Unity MCP window immediately fixes it, confirming the issue is in Unity-side socket state management.

Environment

  • Unity 2021.3.45f2 (macOS)
  • MCP for Unity v9.4.7-beta.8
  • Stdio transport, port 6404
  • Claude Code client

Notes

  • This is not related to PR feat(stdio): add MCP tool toggle support with tools/list_changed notifications #763 (tool toggle). The socket listener and command processing code in StdioBridgeHost are untouched by that PR.
  • telemetry_ping appears to succeed during the failure because it's handled server-side without a Unity round-trip.
  • Reproduced on 2026-02-19. A previous session showed a different failure mode ("Discovered 0 Unity instances") which may be a separate intermittent issue or the same underlying cause manifesting differently.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions