Title: mcpx: daemon restart (POST /v1/daemon/restart) re-execs without waiting for background orphan-session DELETEs — PR #299's wait misses the exec exit path · Issue #301 · developing-today/code · GitHub
Open Graph Title: mcpx: daemon restart (POST /v1/daemon/restart) re-execs without waiting for background orphan-session DELETEs — PR #299's wait misses the exec exit path · Issue #301 · developing-today/code
X Title: mcpx: daemon restart (POST /v1/daemon/restart) re-execs without waiting for background orphan-session DELETEs — PR #299's wait misses the exec exit path · Issue #301 · developing-today/code
Description: Problem PR #299 (merged 2026-10-18, merge commit 4bf48d4e) fixed #298 by retaining the committed takeover's Adoption on the Server and waiting for its background orphan-session DELETEs — bounded by defaults.UpstreamSessionDeleteTimeout (...
Open Graph Description: Problem PR #299 (merged 2026-10-18, merge commit 4bf48d4e) fixed #298 by retaining the committed takeover's Adoption on the Server and waiting for its background orphan-session DELETEs — bounded by...
X Description: Problem PR #299 (merged 2026-10-18, merge commit 4bf48d4e) fixed #298 by retaining the committed takeover's Adoption on the Server and waiting for its background orphan-session DELETEs — bounde...
Opengraph URL: https://github.com/developing-today/code/issues/301
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"mcpx: daemon restart (POST /v1/daemon/restart) re-execs without waiting for background orphan-session DELETEs — PR #299's wait misses the exec exit path","articleBody":"## Problem\n\nPR #299 (merged 2026-10-18, merge commit `4bf48d4e`) fixed #298 by retaining the committed takeover's `Adoption` on the `Server` and waiting for its background orphan-session DELETEs — bounded by `defaults.UpstreamSessionDeleteTimeout` (5s) — on the orderly exit paths. It added the wait to exactly two places (verified on current main `4bf48d4e`):\n\n- `Server.shutdown()` — `pkgs/mcpx/internal/daemon/server.go:512`\n- `Serve()`'s handed-off return — `pkgs/mcpx/internal/daemon/server.go:428`\n\n**A third orderly exit path was missed: the daemon's own restart.** `handleDaemonRestart` (`POST /v1/daemon/restart`, `server.go:1183`; the client call behind `mcpx restart --daemon` is `internal/cli/client.go:754`) re-executes the daemon in place:\n\n```go\ngo func() {\n time.Sleep(defaults.DaemonRestartSettle) // 100ms, defaults.json plumbing.daemonRestartSettle\n if s.reg != nil { ... SaveCache() ... }\n execPath, err := os.Executable()\n if err == nil {\n s.stopServing()\n _ = os.Remove(s.paths.Socket)\n s.paths.RemoveInfo()\n if execErr := execSelf(execPath, os.Args, os.Environ()); ... // server.go:1204, syscall.Exec\n }\n p.Signal(syscall.SIGTERM) // only reached when exec did NOT happen\n}()\n```\n\nThere is no `waitOrphanTerminations()` anywhere in this path (on main, the only call sites are the two above). `syscall.Exec` replaces the process image instantly: every goroutine dies, including any background orphan-session DELETE that `Adoption.Attach()` started after this daemon's takeover. The SIGTERM fallback does not help — it only runs when the exec *didn't* happen; a successful exec never returns.\n\nThe 100ms settle does not incidentally cover this: each orphan DELETE is bounded only by the 5s `upstream.sessionDeleteTimeout` (`internal/mcpclient/http.go` `closeSession`, via `defaults.UpstreamSessionDeleteTimeout`), so a DELETE started at takeover can still be in flight ~4.9s after the restart request lands.\n\n## Why it matters\n\nThis is exactly the leak #298/#299 set out to close — a successor daemon exiting inside the DELETE window loses the DELETE and the removed server's session leaks upstream until expiry, defeating #260's exactly-one-DELETE guarantee in the unreachable-upstream case — on the one exit path whose entire purpose is restarting the daemon. #298's own scenario list names \"a quick upgrade/restart\": a daemon that just took over (e.g. after an upgrade) and is then restarted via `mcpx restart --daemon` — the command the daemon-version notice from #265/PR #266 tells users to run — inside the 5s window hits it.\n\nNote: the identical `handleDaemonRestart` body exists in dezren39/nix's mcpx copy (same route, same exec-without-wait shape); that repo's #409 fix should check this path too.\n\n## Suggested fix\n\nCall `s.waitOrphanTerminations()` in `handleDaemonRestart`'s goroutine before `execSelf` (e.g. right after the settle / before `stopServing()`), reusing the bounded wait #299 added. On the exec-failure fallthrough nothing changes: the process SIGTERMs itself and `shutdown()` already waits there.\n\n## Acceptance criteria\n\n- [ ] After a takeover that orphans a session whose DELETE is blocked/slow, a `POST /v1/daemon/restart` does not exec until the DELETE has completed (or the bounded wait expires and is logged); the upstream still sees exactly one DELETE.\n- [ ] A daemon that never took over (or whose takeover aborted) restarts exactly as before — no added delay.\n- [ ] Regression coverage in the style of #299's `TestSuccessorShutdownWaitsForABlockedOrphanTermination`: blocked-DELETE takeover followed by the restart handler, asserting the (stubbed) `execSelf` is not invoked while the DELETE is blocked. (`execSelf` is already a replaceable var, `server.go:1181`.)\n- [ ] `go test ./internal/daemon/ ./internal/pool/` green.\n\nFound by the pr-diff-review job reviewing PR #299 (commits + diff, open at review start, merged during the run).\n","author":{"url":"https://github.com/dezren39","@type":"Person","name":"dezren39"},"datePublished":"2026-10-18T18:18:28Z","url":"https://github.com/developing-today/code/issues/301"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:cadd5b94-0d9d-8d6b-3446-a0a96772fbab |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 93F4:2D919D:A996EF:DB4FDA:6B063656 |
| html-safe-nonce | d9e4f14fb9b5fa61db29c3bedca80c56e3553982ea2d0c1938156c7237b394b8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5M0Y0OjJEOTE5RDpBOTk2RUY6REI0RkRBOjZCMDYzNjU2IiwidmlzaXRvcl9pZCI6IjM0ODA3MjE3OTcxODI1MzUyNTQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 3d8618c40792bfdbbccca40e8de37523e3cc1d5989d57395d3053bb03f507d1f |
| hovercard-subject-tag | issue:5912635631 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/developing-today/code/301/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d547b5ab75bc8e5de942e4e4229dd2787fc7e44197fc2813e6ed7df3e277a00c/developing-today/code/issues/301 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d547b5ab75bc8e5de942e4e4229dd2787fc7e44197fc2813e6ed7df3e277a00c/developing-today/code/issues/301 |
| og:image:alt | Problem PR #299 (merged 2026-10-18, merge commit 4bf48d4e) fixed #298 by retaining the committed takeover's Adoption on the Server and waiting for its background orphan-session DELETEs — bounded by... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dezren39 |
| hostname | github.com |
| expected-hostname | github.com |
| None | c3584c853cd39700ecff6e2cf8364295ffdb5313e571046c41cd2479270f7df0 |
| turbo-cache-control | no-preview |
| go-import | github.com/developing-today/code git https://github.com/developing-today/code.git |
| octolytics-dimension-user_id | 26439447 |
| octolytics-dimension-user_login | developing-today |
| octolytics-dimension-repository_id | 627308783 |
| octolytics-dimension-repository_nwo | developing-today/code |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 627308783 |
| octolytics-dimension-repository_network_root_nwo | developing-today/code |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9eb3bb1597d09170a5f282cd38ae376dee1a5ec1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width