You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
mcpx: EnsureDaemon ignores a cancelled context — spawns a daemon and waits out the full 20s autostart timeout #284
Client.EnsureDaemon (pkgs/mcpx/internal/cli/client.go:327) ignores a cancelled context:
It never checks ctx.Err(). A failed Ping is always read as "no daemon", even when the ping failed because the caller's context was already cancelled.
It then starts a daemon process the caller no longer wants.
The readiness poll loop (client.go:381-387) never selects on ctx.Done() — it sleeps autostart.pollInterval and re-pings with the cancelled context (which always fails), so it waits out the full autostart.connectTimeout (20s by default, pkgs/mcpx/internal/defaults/defaults.json:181) and finally returns the misleading error daemon did not become ready, not context.Canceled.
So a call cancelled early (e.g. a notifications/cancelled over mcpx serve, or a user hitting Ctrl-C during autostart) takes ~20s to unwind and can leave an unwanted daemon running.
(The same defect is tracked for the dezren39/nix copy of mcpx as dezren39/darwin-nix#233; this repo's client.go is byte-identical except for an issue-reference comment, and the defect is untracked here.)
Evidence (reproduced on main 228019a1)
A test in internal/cli constructs a client with autostart.bin set to a fake binary that only records that it was spawned, autostart.connectTimeout=3s, and calls EnsureDaemon with an already-cancelled context:
elapsed=3.026s err=daemon did not become ready; see .../state/daemon.log
spawnedFakeDaemon=true
Expected: prompt return of context.Canceled, no daemon spawned. Observed: full timeout waited, daemon spawned, wrong error.
Suggested fix
Check ctx.Err() at the top of EnsureDaemon and again after a failed Ping, before treating the failure as "no daemon" / starting one.
In the poll loop, stop on ctx.Done() (select on it alongside the poll sleep) and return ctx.Err().
Acceptance criteria
EnsureDaemon with an already-cancelled context returns context.Canceled promptly (<1s) and does not start a daemon.
Cancelling the context while EnsureDaemon is waiting for a started daemon to become ready returns context.Canceled promptly instead of waiting out autostart.connectTimeout.
Normal behaviour is unchanged: a reachable daemon returns nil, an unreachable one is still auto-started and awaited, and a daemon that never becomes ready still fails with daemon did not become ready after the timeout.
Regression tests cover both cancellation cases; go test ./internal/cli/ passes.
Activity
Merge pull request #285 from developing-today/creator/284-ensure-daem…