Skip to content

Commit b22f43c

Browse files
authored
Merge pull request #614 from jflan-dd/jflan/pipe-overfill
Drain stdout pipe while command is running
2 parents 8f0bf9d + e4e7167 commit b22f43c

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
## Master
1515

16+
- Drain stdout while shell commands are running to prevent execution from locking up if there's too much output [@jflan-dd][] - [#614](https://github.com/danger/swift/pull/614)
17+
1618
## 3.20.0
1719
- Remove deprecated `lint` function with `lintAllFiles` flag [@417-72KI][] - [#622](https://github.com/danger/swift/pull/622)
1820
- Updated Swift 6 build process: Danger files moved to .build/debug/Modules, and SwiftFormat module map conflict resolved by adjusting the Swift import search path. [@abhi-m-simformsolutons][] -[#626](https://github.com/danger/swift/pull/626)

Sources/DangerShellExecutor/ShellExecutor.swift

+8-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,11 @@ public struct ShellExecutor: ShellExecuting {
6161
let pipe = Pipe()
6262
task.standardOutput = pipe
6363
task.launch()
64-
task.waitUntilExit()
6564

6665
let data = pipe.fileHandleForReading.readDataToEndOfFile()
66+
67+
task.waitUntilExit()
68+
6769
return String(data: data, encoding: .utf8)!.trimmingCharacters(in: .whitespacesAndNewlines)
6870
}
6971

@@ -83,19 +85,22 @@ public struct ShellExecutor: ShellExecuting {
8385
let stderr = Pipe()
8486
task.standardError = stderr
8587
task.launch()
86-
task.waitUntilExit()
8788

8889
// Pull out the STDOUT as a string because we'll need that regardless
8990
let stdoutData = stdout.fileHandleForReading.readDataToEndOfFile()
9091
let stdoutString = String(data: stdoutData, encoding: .utf8)!
9192

93+
// Read from STDERR to ensure the `Pipe` does not fill up
94+
let stderrData = stderr.fileHandleForReading.readDataToEndOfFile()
95+
96+
task.waitUntilExit()
97+
9298
// 0 is no problems in unix land
9399
if task.terminationStatus == 0 {
94100
return stdoutString.trimmingCharacters(in: .whitespacesAndNewlines)
95101
}
96102

97103
// OK, so it failed, raise a new error with all the useful metadata
98-
let stderrData = stderr.fileHandleForReading.readDataToEndOfFile()
99104
let stderrString = String(data: stderrData, encoding: .utf8)!
100105

101106
throw SpawnError.commandFailed(command: command,

0 commit comments

Comments
 (0)