Skip to content

Commit

Permalink
[Release Tooling] Fix bug where process is frozen when running comman…
Browse files Browse the repository at this point in the history
…ds with chatty outputs (#12160)
  • Loading branch information
ncooke3 authored Nov 30, 2023
1 parent b2a7d24 commit 6c5a96a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion ReleaseTooling/Sources/Utils/ShellUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,24 @@ public extension Shell {
print("----------------- COMMAND OUTPUT -----------------")
}
task.launch()
// If we are not outputting to the console, there is a possibility that
// the output pipe gets filled (e.g. when running a command that generates
// lots of output). In this scenario, the process will hang and
// `task.waitUntilExit()` will never return. To work around this issue,
// calling `outHandle.readDataToEndOfFile()` before `task.waitUntilExit()`
// will read from the pipe until the process ends.
var outData: Data!
if !outputToConsole {
outData = outHandle.readDataToEndOfFile()
}

task.waitUntilExit()
if outputToConsole { print("----------------- END COMMAND OUTPUT -----------------") }

let fullOutput: String
if outputToConsole {
fullOutput = output.joined(separator: "\n")
} else {
let outData = outHandle.readDataToEndOfFile()
// Force unwrapping since we know it's UTF8 coming from the console.
fullOutput = String(data: outData, encoding: .utf8)!
}
Expand Down

0 comments on commit 6c5a96a

Please sign in to comment.