Different approach, only listen on stdin when LOG_LEVEL=debug (which

is where dropping to a debugger is important).
This commit is contained in:
Nicolas Patry 2024-10-01 17:02:33 +02:00
parent 6d9515578f
commit 41e674eea9
No known key found for this signature in database
GPG Key ID: 64AF4752B2967863

View File

@ -915,6 +915,7 @@ fn shard_manager(
} }
}); });
// We read stdin in another thread as it seems that lines() can block in some cases // We read stdin in another thread as it seems that lines() can block in some cases
if LevelFilter::current() >= tracing::Level::DEBUG {
thread::spawn(move || { thread::spawn(move || {
let mut stdin = io::stdin(); // We get `Stdin` here. let mut stdin = io::stdin(); // We get `Stdin` here.
loop { loop {
@ -922,12 +923,11 @@ fn shard_manager(
if let Ok(n) = stdin.read(&mut buffer) { if let Ok(n) = stdin.read(&mut buffer) {
if n > 0 { if n > 0 {
let _ = pstdin.write_all(&buffer[..n]); let _ = pstdin.write_all(&buffer[..n]);
} else {
break;
} }
} }
} }
}); });
}
let mut ready = false; let mut ready = false;
let start_time = Instant::now(); let start_time = Instant::now();
@ -1065,8 +1065,6 @@ fn log_lines<R: Sized + Read>(mut bufread: BufReader<R>) {
} }
} }
} }
} else {
break;
} }
} }
} }