Skip to content

Commit 14f3387

Browse files
committed
fix: remove premature stream cancellation from DisposableProcess
The previous approach cancelled streams in DisposableProcess cleanup, but this was too early - bash.ts was still reading from them. Streams close naturally when the process exits, so no explicit cancellation is needed. The key fix is that bash.ts now awaits exitCode (which resolves after process exits), then immediately cleans up readline interfaces and Node streams. This prevents waiting for stream 'close' events that don't propagate over SSH.
1 parent df54736 commit 14f3387

File tree

2 files changed

+4
-20
lines changed

2 files changed

+4
-20
lines changed

src/runtime/LocalRuntime.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,8 @@ export class LocalRuntime implements Runtime {
8888
const stderr = Readable.toWeb(childProcess.stderr) as unknown as ReadableStream<Uint8Array>;
8989
const stdin = Writable.toWeb(childProcess.stdin) as unknown as WritableStream<Uint8Array>;
9090

91-
// Register cleanup for streams when process exits
92-
// CRITICAL: These streams MUST be cancelled when process exits to prevent hangs
93-
disposable.addCleanup(() => {
94-
// eslint-disable-next-line @typescript-eslint/no-empty-function
95-
stdout.cancel().catch(() => {});
96-
// eslint-disable-next-line @typescript-eslint/no-empty-function
97-
stderr.cancel().catch(() => {});
98-
});
91+
// No stream cleanup in DisposableProcess - streams close naturally when process exits
92+
// bash.ts handles cleanup after waiting for exitCode
9993

10094
// Track if we killed the process due to timeout or abort
10195
let timedOut = false;

src/runtime/SSHRuntime.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,8 @@ export class SSHRuntime implements Runtime {
179179
const stderr = Readable.toWeb(sshProcess.stderr) as unknown as ReadableStream<Uint8Array>;
180180
const stdin = Writable.toWeb(sshProcess.stdin) as unknown as WritableStream<Uint8Array>;
181181

182-
// Register cleanup for streams when process exits
183-
// CRITICAL: These streams MUST be cancelled when process exits to prevent hangs
184-
// from waiting for stream 'close' events that don't reliably propagate over SSH
185-
disposable.addCleanup(() => {
186-
// Cancel streams to immediately signal EOF
187-
// Use catch to ignore errors if streams are already closed
188-
// eslint-disable-next-line @typescript-eslint/no-empty-function
189-
stdout.cancel().catch(() => {});
190-
// eslint-disable-next-line @typescript-eslint/no-empty-function
191-
stderr.cancel().catch(() => {});
192-
// Don't abort stdin - it's already closed/aborted by bash tool
193-
});
182+
// No stream cleanup in DisposableProcess - streams close naturally when process exits
183+
// bash.ts handles cleanup after waiting for exitCode
194184

195185
// Track if we killed the process due to timeout or abort
196186
let timedOut = false;

0 commit comments

Comments
 (0)