-
-
Notifications
You must be signed in to change notification settings - Fork 224
fix(command-mode): drain process output concurrently to prevent TerminalService pipe deadlock #430
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,12 +108,23 @@ final class TerminalService { | |
| } | ||
| } | ||
|
|
||
| // Drain stdout and stderr concurrently while the process is still | ||
| // running. A child that writes more than the pipe buffer (~64KB) | ||
| // blocks on write() until its output is read, so reading only after | ||
| // waitUntilExit() would deadlock until the timeout fired and return | ||
| // truncated output. Background reads keep both pipes drained so the | ||
| // process can run to completion. | ||
| let outputHandle = outputPipe.fileHandleForReading | ||
| let errorHandle = errorPipe.fileHandleForReading | ||
| async let pendingOutput = Task.detached { outputHandle.readDataToEndOfFile() }.value | ||
| async let pendingError = Task.detached { errorHandle.readDataToEndOfFile() }.value | ||
|
Comment on lines
+119
to
+120
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Command Mode runs a command that produces unbounded or very high-volume output, such as Useful? React with 👍 / 👎. |
||
|
|
||
| let outputData = await pendingOutput | ||
| let errorData = await pendingError | ||
|
|
||
| process.waitUntilExit() | ||
| timeoutTask.cancel() | ||
|
|
||
| let outputData = outputPipe.fileHandleForReading.readDataToEndOfFile() | ||
| let errorData = errorPipe.fileHandleForReading.readDataToEndOfFile() | ||
|
|
||
| let output = String(data: outputData, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) ?? "" | ||
| let errorOutput = String(data: errorData, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When Command Mode runs a command that produces unbounded or very large output, such as
yesor a verbose build that runs until the 30s timeout, these detached reads now keep the pipes drained while accumulating the entire stream inDatabefore returning. That removes the previous OS-pipe-buffer cap, so the app can allocate hundreds of MB/GB and be killed before the timeout; please keep draining but impose a maximum captured byte count/truncation policy.Useful? React with 👍 / 👎.