Skip to content

stdio client keeps dialing a dead port after domain reload — cache TTL + backoff ignore the status file the editor already wrote #1339

Description

@BatuBoyGG

In batch-mode sessions, every script-recompiling refresh triggers a domain reload that kills the stdio bridge listener. The editor side handles this well: StdioBridgeHost retries the old port for BusyPortFallbackWindowSeconds (3 s), can't rebind because the socket is in TIME_WAIT (~30 s on macOS, and ExclusiveAddressUse = true is deliberate per #1173), walks to the next port, and immediately announces the new port via the status file — exactly as its own warning log says: "clients follow via the status file."

The Python server doesn't follow promptly. Two compounding delays:

  1. port_registry_ttl (5.0, core/config.py, no override available) — after the reload, the client keeps dialing the dead cached port until the TTL expires, even though the status file already names the live port.
  2. Exponential reconnect backoff — by the time the editor is back (~4 s of real reload work), the client is sleeping and overshoots.

Measured on macOS / Unity 2022.3.62f2 / mcpforunityserver 10.1.2, batch mode: ~12–15 s of reconnect latency per reload against ~4 s of actual reload work, deterministically on every reload (an automated pipeline of ours pays it 1–3 times per job; the editor walked 6400 → 6401 → 6402 across two reloads in one session, recovery always correct, just slow).

Proposed fix

On connection refused/reset, treat the cached discovery as invalid immediately — re-read the status registry before entering backoff. The fresh port is already on disk at that moment; the current code just doesn't look.

Alternatively (or additionally): make port_registry_ttl and BusyPortFallbackWindowSeconds configurable via environment variables so automated hosts can tune them.

Happy to provide editor logs / timings from the runs where we measured this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions