GeezerVison is showing github.com — mcpx: orphan-session DELETEs from #267 run synchronously on the takeover path, delaying daemon start up to 5s per removed server · Issue #291 · developing-today/code
mcpx: orphan-session DELETEs from #267 run synchronously on the takeover path, delaying daemon start up to 5s per removed server #291
Description
Finding (from PR diff review of #267)
PR #267 ends a removed server's orphaned upstream session with a synchronous HTTP DELETE during takeover — on the critical path, before the successor daemon starts serving.
Evidence (verified on current main 60f7a634)
pkgs/mcpx/internal/daemon/registry_handoff.go, Adoption.Attach(): loops over a.orphanSessions and calls pool.TerminateOrphanedSession(s.server, s.h) synchronously, in series.
pkgs/mcpx/internal/daemon/takeover.go (~line 664): ad.Attach() is called before s.startHTTP() — so every orphan DELETE delays the successor daemon accepting/serving connections.
pool.TerminateOrphanedSession → mcpclient.TerminateHTTPSession → HTTPTransport.closeSession (pkgs/mcpx/internal/mcpclient/http.go): the DELETE is bounded by defaults.UpstreamSessionDeleteTimeout = 5s (pkgs/mcpx/internal/defaults/defaults.json: upstream.sessionDeleteTimeout: "5s").
- Worst case is therefore ~5s per orphaned session, in series: removing several servers from the configuration at once, where an upstream is unreachable in the worst way (packets dropped, not refused — a refused connection fails fast, a blackholed one burns the full timeout), delays the takeover by N × 5s. The case that costs the most is exactly the case where the DELETE can never succeed — cleanup for a dead server blocks the live daemon.
- Termination is explicitly best-effort in the PR's design: failure is already handled by logging
upstream.session.orphaned and leaving the session to expire upstream. Nothing about correctness requires it to complete before the daemon serves — only the abort path requires that no DELETE is sent before commit, which moving the sends to after commit/start preserves.
Why it matters
A takeover is a daemon upgrade/restart: the window where the daemon is not yet serving is user-visible downtime for every connected client. Best-effort cleanup of sessions for servers that no longer exist should never extend that window, least of all when the upstream is dead.
Acceptance criteria
- Orphan-session termination no longer blocks the takeover's serving path: e.g. the DELETEs run after
startHTTP() (still strictly after handoff commit), or concurrently under one bounded overall budget.
- The abort path still sends no DELETE and the predecessor keeps its sessions (existing
TestAbortedTakeoverLeavesARemovedServersSessionAlone passes).
- Exactly one DELETE per orphaned session is still sent after a committed takeover, and
upstream.session.terminated / upstream.session.orphaned lifecycle events are still emitted (existing takeover/orphan tests pass, adapted for any async completion).
- A test or benchmark demonstrates a takeover with an unreachable orphan upstream completes serving without waiting out the per-session DELETE timeout.
Metadata
Metadata
Development
No branches or pull requestsIssue actions