fix(runtime): close lifecycle teardown races

This commit is contained in:
Tianyi Cui
2026-07-29 02:40:02 +08:00
parent c17727d43d
commit 32bce339da
20 changed files with 233 additions and 36 deletions

View File

@@ -473,17 +473,23 @@ export class LocalPtySession implements PtyBackendSession {
this.active = undefined
}
private failActive(error: unknown): void {
private failActive(error: unknown, retainOwnership = false): void {
const operation = this.active
if (operation === undefined) return
this.clearActive()
if (retainOwnership) {
this.stopPolling()
this.activeAbort?.()
this.activeAbort = undefined
} else {
this.clearActive()
}
operation.fail(error)
}
private interrupt(operation: LocalSendOperation): void {
if (this.active !== operation) return
void this.terminal.signalForeground('SIGINT').catch((error: unknown) => {
if (this.active === operation) this.failActive(error)
if (this.active === operation) this.failActive(error, this.writing === operation)
})
}