Skip to content

shell: fix hang when a tool command backgrounds a child process#2462

Merged
dgageot merged 1 commit intodocker:mainfrom
dgageot:fix-shell-bg
Apr 18, 2026
Merged

shell: fix hang when a tool command backgrounds a child process#2462
dgageot merged 1 commit intodocker:mainfrom
dgageot:fix-shell-bg

Conversation

@dgageot
Copy link
Copy Markdown
Member

@dgageot dgageot commented Apr 18, 2026

When a shell command backgrounds a grandchild (e.g. docker run ... &), the grandchild inherits the stdout/stderr pipe fds created by exec.Cmd for non-*os.File writers. cmd.Wait() then blocks until EOF on those pipes, which never comes while the grandchild holds them open — making the tool call hang until the configured timeout (observed wedging an eval run for minutes after the agent ran a detached docker run).

Set cmd.WaitDelay to 500ms in runNativeCommand so that once the direct shell child has exited, Go force-closes the pipe read ends and Wait() returns promptly. The grandchild is left untouched — exactly what the user's & intended.

Add two regression tests covering the plain backgrounded-child case and the detached (setsid) variant where the process-group kill fallback cannot rescue us.

Assisted-By: docker-agent

When a shell command backgrounds a grandchild (e.g. `docker run ... &`),
the grandchild inherits the stdout/stderr pipe fds created by exec.Cmd
for non-*os.File writers. cmd.Wait() then blocks until EOF on those
pipes, which never comes while the grandchild holds them open — making
the tool call hang until the configured timeout (observed wedging an
eval run for minutes after the agent ran a detached `docker run`).

Set cmd.WaitDelay to 500ms in runNativeCommand so that once the direct
shell child has exited, Go force-closes the pipe read ends and Wait()
returns promptly. The grandchild is left untouched — exactly what the
user's `&` intended.

Add two regression tests covering the plain backgrounded-child case
and the detached (setsid) variant where the process-group kill
fallback cannot rescue us.

Assisted-By: docker-agent
@dgageot dgageot requested a review from a team as a code owner April 18, 2026 07:03
@dgageot dgageot merged commit 6ce280c into docker:main Apr 18, 2026
9 checks passed
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.

2 participants