Skip to content

[BUG] A pipeline hangs forever, past the timeout, when a later stage writes more than 64 stderr lines without reading stdin #366

Open

Description

@strandly-the-agent

Checks

  • I have updated to the latest minor and patch version of Strands Shell (built from main @ 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

dbb6189 (--version prints 0.0.0)

Language Runtime Version

Rust 1.100.0

Operating System

Linux 6.18 (aarch64)

Installation Method

built from source

Steps to Reproduce

One strands-shell -c '...' run in the default virtual filesystem:

a=""; i=1; while [ $i -le 65 ]; do a="$a nodir/$i"; i=$((i+1)); done
i=1; while [ $i -le 65 ]; do echo "line $i"; i=$((i+1)); done > lines
grep line lines | rm $a
echo "rc=$?"

Expected Behavior

Same as bash: 65 rm errors on stderr, then rc=1, straight away.

Actual Behavior

No output, and the shell never returns. I killed it after 10 s (it was using a full CPU). With [limits] timeout = 2 in the config it still ran until I killed it at 10 s; the same config stops sleep 100 after 2 s.

The threshold is exact: with 64 operands instead of 65 the script prints the errors and rc=1 at once.

Additional Context

Found while reviewing #354. On main I reproduced it with rm, which reports each failing operand and keeps going; I did not look for other commands that can write that many stderr lines. #354 makes cat and mkdir do the same, so grep line lines | mkdir $a and grep line lines | cat $a (same script, 65 failing operands) return on main and hang on that PR's head 4946e4b. The rest of the #335 follow-ups (tee, rmdir, chmod, cp, sed -i, wc) will reach it the same way.

It needs all three: the command is not the first stage, it writes 65 or more separate stderr lines, and the stage before it writes 65 or more chunks that nobody reads. A subagent that ran more shapes for the #354 review reported no hang when stderr is redirected (2>/dev/null, 2>file), when the command is the first stage, or when it sits inside { }, ( ), a function or a while; I did not re-run those.

Possible Solution

Read from the code, not confirmed with a debugger:

  • Each stage gets a 64-slot stderr channel (src/exec.rs:4163), and one task drains those channels in stage order (src/exec.rs:4401-4406), so stage 2's channel is not read until stage 1 has finished.
  • Stage 1 can't finish: its 64-slot stdout pipe (src/exec.rs:4147) is full and stage 2 never reads it.
  • Stage 2 then fills its stderr channel, and the write retries in a busy loop (src/os.rs:1266-1270), which would explain the CPU use.

Draining every stage's stderr concurrently would break the cycle. I have not looked at why the timeout does not fire. I have not written or tested a fix.

Related Issues

#354, #335

Activity

  1. added
    bug
    on Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    Fields

    Language

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions