fix: close all E2B terminals when a sandbox is closed

This commit is contained in:
James Murdza 2024-10-19 05:44:30 -06:00
parent ad9457b157
commit cc8e0ce187

View File

@ -72,7 +72,6 @@ let isOwnerConnected = false
const containers: Record<string, Sandbox> = {}
const connections: Record<string, number> = {}
const terminals: Record<string, Terminal> = {}
const dirName = "/home/user"
@ -210,6 +209,8 @@ io.on("connection", async (socket) => {
}
)
const terminals: Record<string, Terminal> = {}
const sandboxFiles = await getSandboxFiles(data.sandboxId)
const projectDirectory = path.posix.join(
dirName,
@ -929,6 +930,14 @@ io.on("connection", async (socket) => {
connections[data.sandboxId]--
}
// Close all terminals for this connection
await Promise.all(
Object.entries(terminals).map(async ([key, terminal]) => {
await terminal.close()
delete terminals[key]
})
)
// Stop watching file changes in the container
Promise.all(
fileWatchers.map(async (handle: WatchHandle) => {