fix: add timeout to sandbox tool execution HTTP calls
Replace timeout=None with configurable timeouts (120s execution, 10s connect) to prevent hung sandbox connections from blocking indefinitely. Configurable via STRIX_SANDBOX_EXECUTION_TIMEOUT and STRIX_SANDBOX_CONNECT_TIMEOUT environment variables.
This commit is contained in:
@@ -17,6 +17,10 @@ from .registry import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
SANDBOX_EXECUTION_TIMEOUT = float(os.getenv("STRIX_SANDBOX_EXECUTION_TIMEOUT", "120"))
|
||||||
|
SANDBOX_CONNECT_TIMEOUT = float(os.getenv("STRIX_SANDBOX_CONNECT_TIMEOUT", "10"))
|
||||||
|
|
||||||
|
|
||||||
async def execute_tool(tool_name: str, agent_state: Any | None = None, **kwargs: Any) -> Any:
|
async def execute_tool(tool_name: str, agent_state: Any | None = None, **kwargs: Any) -> Any:
|
||||||
execute_in_sandbox = should_execute_in_sandbox(tool_name)
|
execute_in_sandbox = should_execute_in_sandbox(tool_name)
|
||||||
sandbox_mode = os.getenv("STRIX_SANDBOX_MODE", "false").lower() == "true"
|
sandbox_mode = os.getenv("STRIX_SANDBOX_MODE", "false").lower() == "true"
|
||||||
@@ -62,10 +66,15 @@ async def _execute_tool_in_sandbox(tool_name: str, agent_state: Any, **kwargs: A
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
timeout = httpx.Timeout(
|
||||||
|
timeout=SANDBOX_EXECUTION_TIMEOUT,
|
||||||
|
connect=SANDBOX_CONNECT_TIMEOUT,
|
||||||
|
)
|
||||||
|
|
||||||
async with httpx.AsyncClient(trust_env=False) as client:
|
async with httpx.AsyncClient(trust_env=False) as client:
|
||||||
try:
|
try:
|
||||||
response = await client.post(
|
response = await client.post(
|
||||||
request_url, json=request_data, headers=headers, timeout=None
|
request_url, json=request_data, headers=headers, timeout=timeout
|
||||||
)
|
)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
response_data = response.json()
|
response_data = response.json()
|
||||||
|
|||||||
Reference in New Issue
Block a user