{"record":{"id":"d43c6c66c8b6acc1","repo":"rtk-ai/rtk","slug":"stdout-streaming-thread-panicked","errorCode":null,"errorMessage":"stdout streaming thread panicked","messagePattern":"stdout streaming thread panicked","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/main.rs","lineNumber":2674,"sourceCode":"                    }\n                    let mut err = std::io::stderr().lock();\n                    err.write_all(&buf[..count])?;\n                    err.flush()?;\n                }\n\n                Ok(captured)\n            });\n\n            let status = child\n                .0\n                .take()\n                .context(\"Child process missing\")?\n                .wait()\n                .context(format!(\"Failed waiting for command: {}\", cmd_name))?;\n\n            let stdout_bytes = stdout_handle\n                .join()\n                .map_err(|_| anyhow::anyhow!(\"stdout streaming thread panicked\"))??;\n            let stderr_bytes = stderr_handle\n                .join()\n                .map_err(|_| anyhow::anyhow!(\"stderr streaming thread panicked\"))??;\n\n            let stdout = String::from_utf8_lossy(&stdout_bytes);\n            let stderr = String::from_utf8_lossy(&stderr_bytes);\n            let full_output = format!(\"{}{}\", stdout, stderr);\n\n            // Track usage (input = output since no filtering)\n            timer.track(\n                &format!(\"{} {}\", cmd_name, cmd_args.join(\" \")),\n                &format!(\"rtk proxy {} {}\", cmd_name, cmd_args.join(\" \")),\n                &full_output,\n                &full_output,\n            );\n\n            core::utils::exit_code_from_status(&status, &cmd_name)\n        }","sourceCodeStart":2656,"sourceCodeEnd":2692,"githubUrl":"https://github.com/rtk-ai/rtk/blob/d977e1c31621fe8704e6500ceeb9c7a0de2b6836/src/main.rs#L2656-L2692","documentation":"In proxy mode rtk spawns capture threads for the child's stdout/stderr and joins them after wait(). If the stdout reader thread panics, join() returns Err and rtk converts it to this anyhow error instead of deadlocking or emitting partial output. It signals an internal defect or extreme edge (e.g. a capture-loop bug on very large output), not a property of the wrapped command — the child's exit status was already collected.","triggerScenarios":"A panic inside the stdout capture thread while proxying output-heavy commands (`rtk proxy cat huge.log`, `rtk proxy npm install` in a big monorepo) — src/main.rs:2676.","commonSituations":"Very large outputs or unusual pipe conditions hitting a bug in the installed rtk version; rare in practice.","solutions":["Re-run the command without rtk (`git log --oneline -20`) — the wrapped command itself did not fail","Reproduce and gather evidence: `rtk --version` plus the exact command and output size, ideally with a backtrace (RUST_BACKTRACE=1)","Update rtk to the latest release (or build from main) and report the panic at the rtk-ai/rtk issue tracker if it persists"],"exampleFix":"# before\nrtk proxy npm run build   # internal stdout thread panic\n\n# after (fallback: direct execution; you lose tracking, not the build)\nnpm run build","handlingStrategy":"fallback","validationCode":"# bash: fall back to direct execution when rtk itself fails\nif ! rtk proxy \"$@\"; then\n  echo 'rtk proxy failed — running command directly' >&2\n  exec \"$@\"\nfi","typeGuard":null,"tryCatchPattern":"# bash: wrap rtk proxy so tooling never hard-depends on it\nif ! out=$(rtk proxy \"$@\" 2>&1); then\n  echo \"rtk proxy internal failure ($?), falling back\" >&2\n  \"$@\"\nelse\n  printf '%s\\n' \"$out\"\nfi","preventionTips":["Pin a known-good rtk version in CI and upgrade deliberately","Run RUST_BACKTRACE=1 when reproducing to capture the thread panic site for a bug report","Design scripts so rtk is an optimization layer, not a single point of failure — always have a direct-execution path"],"tags":["proxy","threads","panic","internal"],"backgroundTag":null,"analyzedSha":"d977e1c31621fe8704e6500ceeb9c7a0de2b6836","analyzedAt":"2026-08-16T05:40:46.291Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}