Skip to content

Ensure std_run fallback timeouts terminate descendant processes #155

Description

@codeforester

Problem

At main commit a107134, the Bash timeout fallback in lib/bash/std/lib_std.sh signals only command_pid. If that command starts a background child, the parent can be terminated and std_run can return 124 while the child continues running.

An isolated repro used a shell function that started /bin/sleep 20 in the background and waited. __std_run_with_timeout_fallback__ 1 worker returned 124, but kill -0 <child-pid> still succeeded afterward.

This violates the documented expectation that --timeout bounds a command attempt and makes fallback behavior weaker than the preferred timeout executable path.

Scope

  • Make the fallback terminate the command and descendants it starts, without signaling unrelated processes in the caller's process group.
  • Preserve the TERM-then-KILL grace-period behavior and final status 124.
  • Document the process-tree contract for timeout execution.
  • Add a regression that forces the fallback and proves a background child is gone before the helper returns.

Acceptance Criteria

  • A timed-out command with a long-running background child leaves neither process alive.
  • TERM-ignoring commands and descendants are killed within the existing bounded grace period.
  • Commands that finish normally still preserve their original status.
  • The focused stdlib tests and full validation pass on macOS and Linux.

Validation

  • bats lib/bash/std/tests/lib_std.bats
  • ./tests/validate.sh
  • git diff --check

Metadata

Metadata

Assignees

Labels

bugSomething is not working

Type

No type

Fields

No fields configured for issues without a type.

Projects

Status
Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions