Skip to content

Commit bf50371

Browse files
committed
Change AsyncProcess stdout/err reads to 4096 instead of Int.max
- this should allow us to consume available in the Pipe as its filled and flushed but the running process. rdar://155634107
1 parent 84b3e6e commit bf50371

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Sources/Basics/Concurrency/AsyncProcess.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,8 @@ package final class AsyncProcess {
517517

518518
group.enter()
519519
stdoutPipe.fileHandleForReading.readabilityHandler = { (fh: FileHandle) in
520-
let data = (try? fh.read(upToCount: Int.max)) ?? Data()
520+
// 4096 is default pipe buffer size so reading in that size seems most efficient and still get output as it available
521+
let data = (try? fh.read(upToCount: 4096)) ?? Data()
521522
if data.count == 0 {
522523
stdoutPipe.fileHandleForReading.readabilityHandler = nil
523524
group.leave()
@@ -532,7 +533,8 @@ package final class AsyncProcess {
532533

533534
group.enter()
534535
stderrPipe.fileHandleForReading.readabilityHandler = { (fh: FileHandle) in
535-
let data = (try? fh.read(upToCount: Int.max)) ?? Data()
536+
// 4096 is default pipe buffer size so reading in that size seems most efficient and still get output as it available
537+
let data = (try? fh.read(upToCount: 4096)) ?? Data()
536538
if data.count == 0 {
537539
stderrPipe.fileHandleForReading.readabilityHandler = nil
538540
group.leave()

0 commit comments

Comments
 (0)