{"record":{"id":"37e36c50cc86dd57","repo":"infiniflow/ragflow","slug":"command-timed-out","errorCode":null,"errorMessage":"Command timed out","messagePattern":"Command timed out","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"agent/sandbox/executor_manager/utils/common.py","lineNumber":32,"sourceCode":"#  limitations under the License.\n#\nimport asyncio\nfrom typing import Tuple\n\n\nasync def async_run_command(*args, timeout: float = 5) -> Tuple[int, str, str]:\n    \"\"\"Safe asynchronous command execution tool\"\"\"\n    proc = await asyncio.create_subprocess_exec(*args, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)\n\n    try:\n        stdout, stderr = await asyncio.wait_for(proc.communicate(), timeout=timeout)\n        if proc.returncode is None:\n            raise RuntimeError(\"Process finished but returncode is None\")\n        return proc.returncode, stdout.decode(), stderr.decode()\n    except asyncio.TimeoutError:\n        proc.kill()\n        await proc.wait()\n        raise RuntimeError(\"Command timed out\")\n    except Exception as e:\n        proc.kill()\n        await proc.wait()\n        raise e\n","sourceCodeStart":14,"sourceCodeEnd":37,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/agent/sandbox/executor_manager/utils/common.py#L14-L37","documentation":"The generic timeout raised by `async_run_command` when the wrapped subprocess does not finish within `timeout` seconds (default 5). The process is killed and reaped before the error is raised. Callers pass various timeouts, e.g. the executor uses 5s for docker mkdir and TIMEOUT+5 for code execution, so the same message covers slow Docker CLI startup and genuinely slow commands.","triggerScenarios":"Any helper call whose subprocess exceeds its deadline: `docker exec mkdir` with an unresponsive Docker daemon or frozen container, or the code-run invocation when the user program blocks past TIMEOUT+5.","commonSituations":"Docker daemon overloaded or restarting; container I/O hung (NFS/fuse mount stall); cold-start latency on first docker invocation; user code with an infinite loop or long computation exceeding the configured execution timeout.","solutions":["Identify which call timed out from the traceback (mkdir vs run) and raise that step's timeout appropriately.","Check Docker daemon health (`docker info`, `systemctl status docker`) if even trivial execs time out.","For code execution timeouts, raise the sandbox TIMEOUT configuration or fix the user code that blocks.","Retry once after the process is killed — transient daemon stalls often clear."],"exampleFix":"# before\nreturncode, stdout, stderr = await async_run_command(*run_args, timeout=TIMEOUT + 5)\n\n# after: distinguish startup slowness from user-code overrun and retry transient stalls\ntry:\n    returncode, stdout, stderr = await async_run_command(*run_args, timeout=TIMEOUT + 5)\nexcept RuntimeError as e:\n    if \"timed out\" not in str(e):\n        raise\n    logger.warning(\"Execution hit %.0fs deadline for task %s\", TIMEOUT + 5, task_id)\n    raise TimeoutError(f\"Code execution exceeded {TIMEOUT + 5}s\") from e","handlingStrategy":"retry","validationCode":"# Cheap daemon liveness probe before real work\nrc, _, _ = await async_run_command(\"docker\", \"version\", \"--format\", \"{{.Server.Version}}\", timeout=5)\nif rc != 0:\n    raise RuntimeError(\"Docker daemon unreachable\")","typeGuard":null,"tryCatchPattern":"import asyncio\n\nasync def run_with_retry(cmd, timeout, attempts=2):\n    for i in range(attempts):\n        try:\n            return await async_run_command(*cmd, timeout=timeout)\n        except RuntimeError as e:\n            if \"timed out\" not in str(e) or i == attempts - 1:\n                raise\n            await asyncio.sleep(1)","preventionTips":["Size the timeout to the slowest legitimate step (docker cold start can take seconds).","Probe the Docker daemon before dispatching bursty workloads.","Bound user code with its own internal timeouts so the outer kill is a last resort.","Distinguish 'Command timed out' from downstream TimeoutErrors in alerting."],"tags":["timeout","asyncio","subprocess","docker"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}