From 8e3a6d1aa6cb7823cd1c0e792db3b1c1ba99e737 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 c58aea4..2277071 100644 --- a/backend/server/src/index.ts +++ b/backend/server/src/index.ts @@ -176,8 +176,9 @@ io.on("connection", async (socket) => { const createdContainer = 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); return true; }