Repository navigation
Description
Checks
- I have updated to the latest minor and patch version of Strands Shell (built from
mainat dbb6189) - I have checked the documentation and this is not expected behavior
- I have searched ./issues and there are no duplicates of my issue
Binding
Rust
Strands Shell Version
0.0.0 (built from source, main dbb6189)
Language Runtime Version
Rust 1.100.0
Operating System
Debian 12 (aarch64)
Installation Method
built from source
Steps to Reproduce
Drop an execute call with a timeout while a redirected group is running, then call execute again on the same shell:
use strands_shell::Shell;
#[test]
fn execute_prints_after_a_cancelled_call() {
let rt = tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap();
let local = tokio::task::LocalSet::new();
rt.block_on(local.run_until(async {
let mut shell = Shell::builder().build().unwrap();
let cancelled = tokio::time::timeout(
std::time::Duration::from_millis(300),
Box::pin(shell.execute("{ sleep 3; } 2>/dev/null")),
)
.await;
assert!(cancelled.is_err());
shell.execute("echo next").await;
assert!(!shell.proc.capture);
assert_eq!(shell.proc.captured_output, "");
}));
}Expected Behavior
The second call prints next to stdout, and shell.proc.capture is false, as it was before the cancelled call.
Actual Behavior
shell.proc.capture is true after the cancelled call. The second call returns 0 and prints nothing; next\n is in shell.proc.captured_output.
| First script | proc.capture after cancel |
echo next printed |
|---|---|---|
sleep 3 |
false | yes |
x=$(sleep 3) |
false | yes |
{ sleep 3; } 2>/dev/null |
true | no |
{ sleep 3; } > f |
true | no |
f() { sleep 3; }; f 2>/dev/null |
true | no |
The results are the same on main at dbb6189 and on #384 at f6a79a4.
Additional Context
Found while reviewing #384; it is not caused by that PR. #384 adds one more place with the same shape (the tail of a compound pipeline inside a capture), so g() { cat; sleep 3; }; { { echo a; } | g; } 2>/dev/null leaves capture off on main and on with #384. With a stdout writer installed, that case also loses the writer, because it is held in a local while the tail runs.
Several places in src/exec.rs set proc.capture = true, await, and then restore it: capture_pipeline_checked (line 1923 at dbb6189), the redirected-group arm of run_capturing_status (line 2269) and run_redirected (line 3301). A dropped future never reaches the restore.
Shell::execute already resets one such field at the start of each call (src/shell.rs:455-456, "A call cancelled inside ! must not leave set -e ignored for the next call").
I did not test Shell::run, or the Python, Node.js or WASM bindings.
Possible Solution
Not tested. Either reset proc.capture at the start of Shell::execute, next to errexit_ignored, or restore it from a drop guard at each of these sites. A reset in execute would not bring back a writer that was moved aside.
Activity