From 41e674eea92ed169af5f6a106e57c73367692cae Mon Sep 17 00:00:00 2001 From: Nicolas Patry Date: Tue, 1 Oct 2024 17:02:33 +0200 Subject: [PATCH] Different approach, only listen on stdin when `LOG_LEVEL=debug` (which is where dropping to a debugger is important). --- launcher/src/main.rs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/launcher/src/main.rs b/launcher/src/main.rs index b9da1714..6facb8af 100644 --- a/launcher/src/main.rs +++ b/launcher/src/main.rs @@ -915,19 +915,19 @@ fn shard_manager( } }); // We read stdin in another thread as it seems that lines() can block in some cases - thread::spawn(move || { - let mut stdin = io::stdin(); // We get `Stdin` here. - loop { - let mut buffer = vec![0; 4096]; - if let Ok(n) = stdin.read(&mut buffer) { - if n > 0 { - let _ = pstdin.write_all(&buffer[..n]); - } else { - break; + if LevelFilter::current() >= tracing::Level::DEBUG { + thread::spawn(move || { + let mut stdin = io::stdin(); // We get `Stdin` here. + loop { + let mut buffer = vec![0; 4096]; + if let Ok(n) = stdin.read(&mut buffer) { + if n > 0 { + let _ = pstdin.write_all(&buffer[..n]); + } } } - } - }); + }); + } let mut ready = false; let start_time = Instant::now(); @@ -1065,8 +1065,6 @@ fn log_lines(mut bufread: BufReader) { } } } - } else { - break; } } }