Compare commits

...
Author SHA1 Message Date
Patrick szymkowiak 09979cf297 fix(grep): close subprocess stdin to prevent memory leak (#897)
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>
2026-04-02 17:21:48 +02:00
+5 -1
View File
@@ -6,6 +6,7 @@ use crate::core::utils::{exit_code_from_output, resolved_command};
use anyhow::{Context, Result};
use regex::Regex;
use std::collections::HashMap;
use std::process::Stdio;
#[allow(clippy::too_many_arguments)]
pub fn run(
@@ -28,7 +29,9 @@ pub fn run(
let rg_pattern = pattern.replace(r"\|", "|");
let mut rg_cmd = resolved_command("rg");
rg_cmd.args(["-n", "--no-heading", &rg_pattern, path]);
rg_cmd
.args(["-n", "--no-heading", &rg_pattern, path])
.stdin(Stdio::null());
if let Some(ft) = file_type {
rg_cmd.arg("--type").arg(ft);
@@ -47,6 +50,7 @@ pub fn run(
.or_else(|_| {
resolved_command("grep")
.args(["-rn", pattern, path])
.stdin(Stdio::null())
.output()
})
.context("grep/rg failed")?;