GeezerVison is showing github.com — mcpx: end orphaned upstream sessions off the takeover serving path (#291) by dezren39 · Pull Request #296 · developing-today/code
Conversation
dezren39
commented
Oct 18, 2026
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Fixes #291.
Problem: Adoption.Attach() ran each orphan-session DELETE synchronously, in series, and takeover.go calls Attach() before startHTTP() — so a takeover was delayed up to 5s (the upstream session DELETE timeout) per removed server, worst exactly when the removed server's upstream is unreachable and the DELETE can never succeed.
Solution: Attach() now starts each termination in a background goroutine — still strictly after handoff commit, so the abort path still sends no DELETE and the predecessor keeps its sessions. New Adoption.WaitOrphanTerminations() lets tests/shutdown wait for the background terminations. Termination remains best-effort: failures still log upstream.session.orphaned, successes upstream.session.terminated, exactly one DELETE per orphan.
This mirrors dezren39/nix PR #404 (fix for dezren39/darwin-nix#402, merged today); the pre-fix registry_handoff.go / registry_handoff_test.go were verified byte-identical between the two repos' pkgs/mcpx copies, with issue refs re-pointed to #291.
Verification:
- New
TestTakeoverOrphanTerminationDoesNotBlockAttach (blackholed upstream handler): Attach returns immediately, DELETE still delivered exactly once in the background — passes.
- Existing
TestTakeoverTerminatesARemovedServersUpstreamSession and TestAbortedTakeoverLeavesARemovedServersSessionAlone pass (abort still sends no DELETE).
- Full
internal/daemon suite green; go build ./... and go vet clean; gofmt clean.
![Autofix with [code]smith](/api/image?u=https%3A%2F%2Fcamo.githubusercontent.com%2Fef26d88456de9cc93cf03b8611c53675c8af4fc8361b0049e62a133b46e853b6%2F68747470733a2f2f70722d636f6d6d656e74732d6173736574732e626c61636b736d6974682e73682f636f6465736d6974682f6175746f6669782d776974682d636f6465736d6974682d6461726b2e737667)
Need help on this PR? Tag @codesmith-bot with what you need.
Summary by CodeRabbit
- Bug Fixes
- Attaching to a daemon no longer waits for orphaned upstream sessions to finish shutting down, helping handoffs complete promptly even when cleanup is delayed.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
)
Adoption.Attach ran each orphan-session DELETE synchronously, in series,
before the successor daemon started serving: N x 5s of takeover downtime
when removed servers' upstreams are unreachable. Termination is already
best-effort (failure logs upstream.session.orphaned and leaves the session
to expire), so Attach now starts each termination in the background —
still strictly after handoff commit, so the abort path still sends no
DELETE. New WaitOrphanTerminations lets tests/shutdown wait for them.
New TestTakeoverOrphanTerminationDoesNotBlockAttach holds a DELETE in a
blackholed upstream handler: Attach returns immediately, the DELETE is
still delivered exactly once in the background. Mirrors dezren39/nix
PR #404 (fix for dezren39/darwin-nix#402); pre-fix files were byte-identical
between the two repos' pkgs/mcpx copies.
Codex Review Summary
This comment shows the latest Codex review activity on this pull request.
| Review |
Status |
Commit |
Review trigger |
| 📝 Code Review |
✅ Completed 2026-10-18T16:06:10.237304Z |
1bb90ba |
PR opened |
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review" or "@codex security review".
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|

Note Currently processing new changes in this PR. This may take a few minutes, please wait...
⚙️ Run configuration
-
- Configuration used: defaults
- Review profile: CHILL
- Plan: Advanced
- Run ID:
05ad4631-1da8-40cf-9ee0-ffefac982f1b
📥 Commits
-
Reviewing files that changed from the base of the PR and between 60f7a63 and 1bb90ba.
📒 Files selected for processing: 2
-
pkgs/mcpx/internal/daemon/registry_handoff.go
pkgs/mcpx/internal/daemon/registry_handoff_test.go
+-------------------------------------------------------------------+
| This refactor is like rearranging furniture during an earthquake. |
+-------------------------------------------------------------------+
\
\ /)/)
( '')
/ |
o(___)
✨ Finishing Touches
-
📝 Generate docstrings
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1bb90ba2b7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Comment on lines
+175
to
+179
|
|
a.orphanWG.Add(1)
|
|
|
go func(s orphanSession) {
|
|
|
defer a.orphanWG.Done()
|
|
|
pool.TerminateOrphanedSession(s.server, s.h)
|
|
|
}(s)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bound orphan-session deletion concurrency
When a removed pool contains many live sessions, this loop starts one goroutine and one outbound DELETE connection for every session at once. Because pool.max has no upper bound and multiple pools may be removed together, a takeover can now create an unbounded connection/FD burst; an upstream with concurrency or rate limits may also reject DELETEs that the previous serial implementation would have completed, leaving sessions alive until expiry. Run the cleanup asynchronously but drain it serially or through a bounded worker pool so serving starts immediately without unbounded fan-out.
Useful? React with 👍 / 👎.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Comment on lines
+187
to
+188
|
|
func (a *Adoption) WaitOrphanTerminations() {
|
|
|
a.orphanWG.Wait()
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Register orphan cleanup with daemon shutdown
This wait hook cannot actually be used by the orderly-shutdown path: commitTakeover keeps the Adoption only in a local variable and discards it on return, while Server.stopServing waits only for registry pools. If the successor is stopped or restarted shortly after takeover—especially while a DELETE is waiting on a slow upstream—the process can exit with the goroutine still running and silently abandon a termination that would otherwise succeed. Track these jobs on a server-owned wait group (or retain the adoption) and wait for them within the shutdown deadline.
Useful? React with 👍 / 👎.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Oct 18, 2026
Uh oh!
There was an error while loading. Please reload this page.
Milestone
No milestone
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|