fix(grep): close subprocess stdin to prevent hook pipe leak (#897)#945
fix(grep): close subprocess stdin to prevent hook pipe leak (#897)#945celstnblacc wants to merge 7 commits intortk-ai:developfrom
Conversation
fix(refacto-codebase): technical docs & sub folders
…aster--components--rtk chore(master): release 0.34.2
When RTK is invoked via Claude Code's PreToolUse hook, the hook keeps its stdin pipe open for the duration of the session. rg/grep subprocesses inherit this open pipe and block waiting for EOF — they never terminate. On macOS with multiple concurrent grep calls this causes memory to accumulate unboundedly, eventually triggering a kernel panic (observed: ~514GB RAM+swap consumed, single process at ~198GB). Fix: redirect subprocess stdin to /dev/null so children are decoupled from the hook pipe and terminate normally after completing their search. Fixes rtk-ai#897 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
newblacc seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
|
Hello @celstnblacc Thanks for the contribution, could you sign the CLA please ? |
|
also this should target develop branch |
|
completed |
|
hey sorry just saw the version bump, this is not in PR scope and done automatically, please remove this and we should be ready to merge |
|
fixed |
|
CLA is not signed, you can sign by clicking the link https://cla-assistant.io/rtk-ai/rtk?pullRequest=945 then ready to merge |
|
Thanks @celstnblacc — correct fix for #897. Note that PR #979 addresses the same issue with the same approach ( |
|
Closing with : #979 Thanks for contributing |
Problem
When RTK is invoked via Claude Code's PreToolUse hook, the hook process keeps its stdin pipe open for the duration of the entire session.
rg/grepsubprocesses inherit this open pipe via the defaultCommandstdin behaviour and block waiting for EOF — they never terminate.On macOS with multiple concurrent grep calls (e.g. a long coding session with many search operations) memory accumulates unboundedly:
Reported in #897.
Root Cause
Rust's
std::process::Commandinherits stdin from the parent process by default. When RTK is a subprocess of the hook runner, its stdin is the hook pipe. Children spawned by RTK inherit the same pipe. Since the hook pipe stays open for the whole session, the children never receive EOF and never exit.Fix
Redirect subprocess stdin to
/dev/nullon both thergprimary path and thegrepfallback:This is a 3-line change. Children now terminate immediately after completing their search, regardless of the parent hook pipe state.
Test plan
cargo fmt --all— no formatting changescargo clippy --all-targets— zero warningscargo test --all— 1145 tests, 0 failuresps -eo pid,rss,comm | sort -k2 -rnto confirm grep processes terminate normallyNotes
Stdio::null()only affects stdin; stdout/stderr are unchanged