fix: close all E2B terminals when a sandbox is closed
This commit is contained in:
parent
ad9457b157
commit
cc8e0ce187
@ -72,7 +72,6 @@ let isOwnerConnected = false
|
|||||||
|
|
||||||
const containers: Record<string, Sandbox> = {}
|
const containers: Record<string, Sandbox> = {}
|
||||||
const connections: Record<string, number> = {}
|
const connections: Record<string, number> = {}
|
||||||
const terminals: Record<string, Terminal> = {}
|
|
||||||
|
|
||||||
const dirName = "/home/user"
|
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 sandboxFiles = await getSandboxFiles(data.sandboxId)
|
||||||
const projectDirectory = path.posix.join(
|
const projectDirectory = path.posix.join(
|
||||||
dirName,
|
dirName,
|
||||||
@ -929,6 +930,14 @@ io.on("connection", async (socket) => {
|
|||||||
connections[data.sandboxId]--
|
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
|
// Stop watching file changes in the container
|
||||||
Promise.all(
|
Promise.all(
|
||||||
fileWatchers.map(async (handle: WatchHandle) => {
|
fileWatchers.map(async (handle: WatchHandle) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user