Skip to content

[Bug]:execute_shell_command deadlocks when subprocess output exceeds pipe buffer #1255

@lpdink

Description

@lpdink

Describe the bug

agentscope.tool.execute_shell_command can deadlock when the child process writes more to stdout/stderr than the OS pipe buffer (often ~64KB). The parent waits for the process to exit with proc.wait() while not reading the pipes; the child blocks on writing once the buffer is full. Neither side progresses.

To Reproduce

  1. Code (async):
import asyncio
from agentscope.tool import execute_shell_command

async def main():
    # GitHub releases API returns a large JSON (often >64KB)
    resp = await execute_shell_command(
        command='curl -s -H "Accept: application/vnd.github+json" '
                '"https://api.github.com/repos/agentscope-ai/agentscope/releases"',
        timeout=60,
    )
    print(resp)

asyncio.run(main())
  1. Run: python repro.py

  2. Observe: The script hangs and never prints. The same curl command runs to completion in a normal terminal.

Expected behavior

The tool should return with <returncode>0</returncode>, <stdout>...</stdout> containing the API response, and no hang.

Error messages

There is no exception or error message; the call simply blocks indefinitely (until timeout, if any).

Environment

  • AgentScope Version: 1.0.13
  • Python Version: 3.12
  • OS: macOS (darwin)

Additional context

Root cause: In _shell.py, the implementation does:

await asyncio.wait_for(proc.wait(), timeout=timeout)
stdout, stderr = await proc.communicate()

Waiting for the process with proc.wait() without reading stdout/stderr allows the pipe buffers to fill. Once they are full, the child blocks on write() and never exits, so proc.wait() never returns → deadlock.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions