agentscope-ai / agentscope-ai/agentscope
[Bug]:`execute_shell_command` deadlocks when subprocess output exceeds pipe buffer
- 主要言語
- Python
- スター
- 31.5k
- フォーク
- 3.5k
- 平均マージ
- 1日 23時間
- マージ済み PR(30日)
- 95
説明
**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):
```python
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())
```
2. **Run:** `python repro.py`
3. **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 `0`, `...` 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:
```python
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.
コントリビューションガイド
評価
この issue はまだ評価されていません。