diff --git a/backend/server/src/index.ts b/backend/server/src/index.ts index f659c7f..9f08b3b 100644 --- a/backend/server/src/index.ts +++ b/backend/server/src/index.ts @@ -72,7 +72,6 @@ let isOwnerConnected = false const containers: Record = {} const connections: Record = {} -const terminals: Record = {} const dirName = "/home/user" @@ -210,6 +209,8 @@ io.on("connection", async (socket) => { } ) + const terminals: Record = {} + 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) => {