fix(grep): close subprocess stdin to prevent memory leak (#897)#979
Merged
fix(grep): close subprocess stdin to prevent memory leak (#897)#979
Conversation
When RTK runs via Claude Code's PreToolUse hook, grep/rg subprocesses inherit the hook's open stdin pipe. They block waiting for EOF and never terminate, accumulating memory unboundedly (reported: 514GB on 96GB Mac, kernel panic). Fix: set stdin(Stdio::null()) on both rg and grep fallback commands so subprocesses get immediate EOF instead of inheriting the parent pipe. Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
4 tasks
aeppling
approved these changes
Apr 3, 2026
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.
Summary
stdin(Stdio::null())on bothrgandgrepfallback subprocess commandsProblem
When RTK runs via Claude Code's PreToolUse hook, grep/rg subprocesses inherit the hook's open stdin pipe. They block waiting for EOF and never terminate, accumulating memory unboundedly. Reported: 8 concurrent grep processes consumed ~514GB (RAM + swap) on a 96GB Mac Studio, triggering a kernel panic.
Fix
3 lines: import
Stdio+.stdin(Stdio::null())on bothCommandinvocations (rg primary + grep fallback).Fixes #897
Test plan
cargo fmt --all— cleancargo clippy --all-targets— no new warningscargo test grep— 11 tests passed