Skip to content

fix(grep): close subprocess stdin to prevent memory leak (#897)#979

Merged
aeppling merged 1 commit intodevelopfrom
fix/grep-stdin-leak
Apr 3, 2026
Merged

fix(grep): close subprocess stdin to prevent memory leak (#897)#979
aeppling merged 1 commit intodevelopfrom
fix/grep-stdin-leak

Conversation

@pszymkowiak
Copy link
Copy Markdown
Collaborator

Summary

  • Set stdin(Stdio::null()) on both rg and grep fallback subprocess commands
  • Prevents grep processes from inheriting the hook's open stdin pipe and blocking indefinitely

Problem

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 both Command invocations (rg primary + grep fallback).

Fixes #897

Test plan

  • cargo fmt --all — clean
  • cargo clippy --all-targets — no new warnings
  • cargo test grep — 11 tests passed

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>
@aeppling aeppling merged commit 7217562 into develop Apr 3, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants