Skip to content

fix: terminate bash process groups on timeout - #304

Merged
lodyai[bot] merged 1 commit into
mainfrom
fix/bash-timeout-process-group
Sep 13, 2026
Merged

lodyai[bot] merged 1 commit into
mainfrom
fix/bash-timeout-process-group

Conversation

@lodyai

@lodyai lodyai Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Bash timeouts currently terminate only the shell, leaving descendants running and holding stdout/stderr pipes open. For example, sleep 6 & echo CHILD_PID=$!; wait with a one-second timeout took 6.07 seconds to return; the child was still alive after the shell received SIGTERM.

This change starts commands in a separate POSIX session and terminates the process group, allowing three seconds for SIGTERM before escalating to SIGKILL. Cleanup also handles descendants whose shell has already exited and bounds output draining to one second. Output finalization now propagates caller cancellation while preserving reader tasks for cleanup. bash.kill always uses termination, including when the shell leader has exited; cancellation and quit share the same cleanup implementation.

The bash tool description documents timeout cleanup and its limits. Descendants that create their own sessions are outside the group; Windows retains single-process termination. Background commands continue to ignore timeout_seconds.

Validation:

  • Full pytest suite: 349 passed, 1 skipped on macOS / Python 3.14.
  • Five new regression cases cover shell-first exit, SIGTERM-resistant descendants, and bounded output draining.
  • Ruff lint and formatting, mypy, and git diff --check passed.

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bub 1970ffb Commit Preview URL

Branch Preview URL
Sep 13 2026, 12:09 AM

@lodyai
lodyai Bot merged commit eccbf7c into main Sep 13, 2026
6 checks passed
@frostming
frostming deleted the fix/bash-timeout-process-group branch September 13, 2026 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant