-
Notifications
You must be signed in to change notification settings - Fork 40
Closed
Description
Right now for builtin/custom commands, we just call the registered functions to get the results instead of spawning separate processes. However, when they are used in pipes, it could become blocking when the pipe is full:
code:
➜ rust_cmd_lib git:(master) ✗ cat examples/one.rs
use cmd_lib::*;
fn main() -> CmdResult {
init_builtin_logger();
use_builtin_cmd!(cat); // remove this line, there will be no blocking
let big_file_content = "a".repeat(64 * 4096 * 2);
std::fs::write("/tmp/big_file", big_file_content)?;
run_cmd!(cat /tmp/big_file | wc)?;
Ok(())
}
output:
➜ rust_cmd_lib git:(master) ✗ CMD_LIB_DEBUG=1 cargo run --example one
Finished dev [unoptimized + debuginfo] target(s) in 0.02s
Running `target/debug/examples/one`
DEBUG - Running ["cat", "/tmp/big_file"] | ["wc"] ...
---> blocking here
We can fix the above bug by launching threads for each builtin/custom commands, however, it seems overkill for other builtin commands like echo/true/info/error/debug/..., and it would also complicate the current code. Need to figure out a way to solve this blocking issue more gracefully.
Metadata
Metadata
Assignees
Labels
No labels