GeezerVison is showing github.com — mcpx: successor daemon never waits for background orphan-session DELETEs on shutdown — WaitOrphanTerminations has no production caller · Issue #298 · developing-today/code
mcpx: successor daemon never waits for background orphan-session DELETEs on shutdown — WaitOrphanTerminations has no production caller #298DescriptionProblem
Since #291 / PR #296, a successor daemon ends a removed server's orphaned upstream HTTP session in background goroutines started by Adoption.Attach() (pkgs/mcpx/internal/daemon/registry_handoff.go, Attach). Adoption.WaitOrphanTerminations() exists to wait for those goroutines — its own doc comment says "Production serving never waits for it; it exists for tests and orderly shutdown", and the orphanWG field comment frames it as for "a shutdown that wants a clean slate".
No production code ever calls it. Verified on main f7efb040:
grep -rn WaitOrphanTerminations pkgs/mcpx/internal/daemon → only the definition (registry_handoff.go:187) and two test callers (registry_handoff_test.go:168, :205).
- The one production
Adoption is a local in commitTakeover (pkgs/mcpx/internal/daemon/takeover.go:637 ad, err := s.reg.Adopt(in.pools), :664 ad.Attach()) and is discarded when commitTakeover returns; the Server struct retains no reference to it.
Server.shutdown() (pkgs/mcpx/internal/daemon/server.go, ~:471) flushes caches, calls stopServing(), removes the socket/record and returns — it never waits for orphan terminations.
Server.Serve()'s handed-off case returns nil directly, after which the caller in pkgs/mcpx/internal/cli/root.go:427 returns and the process exits — that path doesn't wait either.
Why it matters
Each orphan DELETE is bounded only by upstream.sessionDeleteTimeout (5s, pkgs/mcpx/internal/defaults/defaults.json:260), and the async move in #291 was motivated exactly by upstreams that never answer. A successor that stops — or hands off again — inside that window (a quick upgrade/restart, an idle-exit daemon, a crash-free short-lived run) exits with the DELETEs still in flight; process exit kills the goroutines, so the session is never ended and leaks upstream until it expires. That silently defeats #260's "exactly one DELETE, post-commit" guarantee in precisely the unreachable-upstream case.
The same code in the dezren39/nix mcpx copy has the identical gap (its WaitOrphanTerminations likewise has test-only callers).
Suggested fix
- Retain the
Adoption from a committed takeover on the Server (e.g. an atomic.Pointer[Adoption] set in commitTakeover after the commit succeeds; the abort path must not retain/wait — it sends no DELETEs by design).
- Wait for orphan terminations on the orderly exit paths:
shutdown(), and the handed-off return in Serve() (that daemon's own orphan DELETEs are not part of the next handoff, so nobody else will finish them).
- Keep the wait bounded in effect: terminations already run in parallel and each is capped by the 5s delete timeout; if a separate overall bound is preferred, make it explicit and log when it expires rather than blocking shutdown indefinitely.
Acceptance criteria
- After a takeover that orphans a session whose DELETE is blocked/slow,
shutdown() does not return until the DELETE has completed (or an explicit bound expires and is logged); the upstream still sees exactly one DELETE.
- The handed-off exit path in
Serve() likewise does not return while this daemon's orphan terminations are in flight.
- A successor that never took over, or whose takeover aborted, shuts down exactly as before (no wait, no DELETE).
- New regression test at the Server level (a blocked-DELETE takeover followed by shutdown), in the style of
registry_handoff_test.go's blackholed-upstream test for mcpx: orphan-session DELETEs from #267 run synchronously on the takeover path, delaying daemon start up to 5s per removed server #291.
-
go test ./internal/daemon/ ./internal/pool/ green; existing takeover/abort tests unchanged and passing.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|