fix: use ThreadPoolExecutor for MCP stdio on all platforms#615
Open
HouMinXi wants to merge 2 commits into
Open
fix: use ThreadPoolExecutor for MCP stdio on all platforms#615HouMinXi wants to merge 2 commits into
HouMinXi wants to merge 2 commits into
Conversation
ProcessPoolExecutor fork server and workers inherit stdin as a Unix socket. When the host disconnects, inherited fds block EOF, producing zombie processes. The existing Windows-only thread fallback (tirth8205#46, tirth8205#136) already solves this. Remove the platform guard so MCP stdio mode uses ThreadPoolExecutor on all platforms. tree-sitter releases GIL during native parsing, so thread parallelism is preserved. CRG_PARSE_EXECUTOR still overrides. Signed-off-by: Minxi Hou <houminxi@gmail.com>
ProcessPoolExecutor fork server and workers inherit stdin as a Unix socket. When the host disconnects, inherited fds block EOF, producing zombie processes. The existing Windows-only thread fallback (tirth8205#46, tirth8205#136) already solves this. Remove the platform guard so MCP stdio mode uses ThreadPoolExecutor on all platforms. tree-sitter releases GIL during native parsing, so thread parallelism is preserved. CRG_PARSE_EXECUTOR still overrides. Signed-off-by: Minxi Hou <houminxi@gmail.com>
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.
fix: use ThreadPoolExecutor for MCP stdio on all platforms
Problem
When code-review-graph runs as an MCP stdio server,
ProcessPoolExecutor creates a fork server (fork+exec) and workers
(fork) that both inherit stdin as a Unix socket to the host. When
the host disconnects, Linux delivers EOF only when all fd references
are closed. The inherited fds keep the socket alive indefinitely --
the server's stdin read loop never terminates, producing zombie
processes (20+ after 8h, ~765MB RSS).
Existing Workaround
_select_executor_kind() already switches to ThreadPoolExecutor on
Windows when stdin is not a TTY (#46, #136). The docstring
explains the rationale: "Tree-sitter parsing in the worker releases
the GIL during native parsing, so the speedup loss for falling back
to threads is small (typically <30% on the full-build path) and the
trade is worth it."
The same logic applies to all Unix platforms. MCP stdio transport
means stdin is a socket, not a TTY, on every platform.
Fix
Remove the
sys.platform == "win32"guard from the thread-fallbackcondition. When stdin is not a TTY (MCP stdio mode), use
ThreadPoolExecutor on all platforms.
ThreadPoolExecutor avoids fork entirely:
parsing)
CRG_PARSE_EXECUTOR=process/thread still overrides.
Testing
Verified end-to-end on Linux (Python 3.14, Fedora 44):