Skip to content

Commit 6c5a96a

Browse files
authored
[Release Tooling] Fix bug where process is frozen when running commands with chatty outputs (#12160)
1 parent b2a7d24 commit 6c5a96a

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

ReleaseTooling/Sources/Utils/ShellUtils.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,24 @@ public extension Shell {
147147
print("----------------- COMMAND OUTPUT -----------------")
148148
}
149149
task.launch()
150+
// If we are not outputting to the console, there is a possibility that
151+
// the output pipe gets filled (e.g. when running a command that generates
152+
// lots of output). In this scenario, the process will hang and
153+
// `task.waitUntilExit()` will never return. To work around this issue,
154+
// calling `outHandle.readDataToEndOfFile()` before `task.waitUntilExit()`
155+
// will read from the pipe until the process ends.
156+
var outData: Data!
157+
if !outputToConsole {
158+
outData = outHandle.readDataToEndOfFile()
159+
}
160+
150161
task.waitUntilExit()
151162
if outputToConsole { print("----------------- END COMMAND OUTPUT -----------------") }
152163

153164
let fullOutput: String
154165
if outputToConsole {
155166
fullOutput = output.joined(separator: "\n")
156167
} else {
157-
let outData = outHandle.readDataToEndOfFile()
158168
// Force unwrapping since we know it's UTF8 coming from the console.
159169
fullOutput = String(data: outData, encoding: .utf8)!
160170
}

0 commit comments

Comments
 (0)