fix: close in-flight connects on session_shutdown - #3
Open
levitte wants to merge 2 commits into
Open
Conversation
The extension spawns the codebase-memory-mcp child process at load time but never closes it. The child's stdio pipes keep the parent event loop alive, so pi in non-interactive print mode (-p / --mode json) hangs forever after answering instead of exiting. Register an idempotent session_shutdown handler (the documented hook for session-scoped resources) that closes the MCP client, letting the event loop drain and the process exit normally. Repro: pi -p "ping" with this extension loaded never exits. After: exits cleanly; interactive sessions are unaffected because session_shutdown only fires at session end/switch, not per turn.
If shutdown lands while connect() is still pending, client is undefined and the handler no-ops; the spawn then completes into a leak that holds the event loop open just the same. Assisted-by: Pi:moonshot/kimi-k3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Stacked on #1 — only the top commit is new here; this PR's diff shrinks to that commit once #1 merges.
#1's
session_shutdownhandler misses one race: if shutdown lands whileconnect()is still in flight,clientis stillundefined, so the handler no-ops and the in-flight spawn completes anyway — its stdio pipes then hold the event loop open just the same, andpi -pstill hangs.Fix: record the shutdown and close the freshly connected client instead of adopting it.
Verified that normal shutdown still exits cleanly:
pi -preturns in ~5 s with the extension loaded (pi 0.84.0).