fix(pty): pty session handle leak (#15599)

This commit is contained in:
kikuchan
2026-03-07 13:53:11 +09:00
committed by GitHub
parent 1a9af8acb6
commit b2c2478d9d
2 changed files with 90 additions and 10 deletions

View File

@@ -195,18 +195,11 @@ export namespace Pty {
session.bufferCursor += excess
})
ptyProcess.onExit(({ exitCode }) => {
if (session.info.status === 'exited') return
log.info("session exited", { id, exitCode })
session.info.status = "exited"
for (const [key, ws] of session.subscribers.entries()) {
try {
if (ws.data === key) ws.close()
} catch {
// ignore
}
}
session.subscribers.clear()
Bus.publish(Event.Exited, { id, exitCode })
state().delete(id)
remove(id)
})
Bus.publish(Event.Created, { info })
return info
@@ -228,6 +221,7 @@ export namespace Pty {
export async function remove(id: string) {
const session = state().get(id)
if (!session) return
state().delete(id)
log.info("removing session", { id })
try {
session.process.kill()
@@ -240,7 +234,6 @@ export namespace Pty {
}
}
session.subscribers.clear()
state().delete(id)
Bus.publish(Event.Deleted, { id })
}