Stop code sandbox on request timeout to allow sandbox process restarts

This commit is contained in:
Debanjum
2025-02-14 13:35:37 +05:30
parent ecc2f79571
commit 701a7be291
2 changed files with 8 additions and 2 deletions

View File

@@ -114,7 +114,7 @@ jobs:
# Start code sandbox
npm install -g pm2
npm run ci --prefix terrarium
NODE_ENV=production npm run ci --prefix terrarium
# Wait for server to be ready
timeout=120

View File

@@ -100,7 +100,13 @@ async def run_code(
logger.info(f"Executed Code\n----\n{code}\n----\nResult\n----\n{cleaned_result}\n----")
yield {query: {"code": code, "results": result}}
except asyncio.TimeoutError as e:
raise ValueError(f"Failed to run code for {query} with Timeout error: {e}")
# Call the sandbox_url/stop GET API endpoint to stop the code sandbox
error = f"Failed to run code for {query} with Timeout error: {e}"
try:
await aiohttp.ClientSession().get(f"{sandbox_url}/stop", timeout=5)
except Exception as e:
error += f"\n\nFailed to stop code sandbox with error: {e}"
raise ValueError(error)
except Exception as e:
raise ValueError(f"Failed to run code for {query} with error: {e}")