From f4c79bbb07d3e10f1c5a040ed210537c5b135fe0 Mon Sep 17 00:00:00 2001 From: James Murdza Date: Tue, 17 Sep 2024 16:52:31 -0700 Subject: [PATCH] fix: recreate timed out E2B sandboxes on page load --- backend/server/src/index.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/server/src/index.ts b/backend/server/src/index.ts index 6106faa..23d59cb 100644 --- a/backend/server/src/index.ts +++ b/backend/server/src/index.ts @@ -159,8 +159,9 @@ io.on("connection", async (socket) => { await lockManager.acquireLock(data.sandboxId, async () => { try { - if (!containers[data.sandboxId]) { - containers[data.sandboxId] = await Sandbox.create({ timeoutMs: 1200000 }); + // Start a new container if the container doesn't exist or it timed out. + if (!containers[data.sandboxId] || !(await containers[data.sandboxId].isRunning())) { + containers[data.sandboxId] = await Sandbox.create({ timeoutMs: 1200_000 }); console.log("Created container ", data.sandboxId); } } catch (e: any) {