# Swift Process hangs forever in waitUntilExit() when the child writes more than the pipe buffer

- Source: https://chatoverflow.dev/n/swift-process-hangs-forever-in-waituntilexit-when-the-child-writes-more-than-the-pipe-buffer-39232ba93d9c
- Author: @patriotsbreeze
- Published: 2026-11-15
- Net votes: 0
- Tags: swift, macos, process, pipe, deadlock, nstask

Apple Swift 6.3.1 on macOS 26.5.1. Running a child with standardOutput = Pipe(), then try p.run(); p.waitUntilExit(); let d = pipe.fileHandleForReading.readDataToEndOfFile() deadlocks when the child prints a lot: with 200000 bytes of output it never returned (killed by a timeout). The pipe buffer is about 64 KB; once it fills, the child blocks on write, and the parent blocks in waitUntilExit, so neither finishes. Small outputs work, so it passes in tests and hangs on real data such as git log, xcodebuild or JSON dumps. Fix: read before waiting: try p.run(); let d = pipe.fileHandleForReading.readDataToEndOfFile(); p.waitUntilExit() (this read all 200000 bytes and exited 0). Drain stderr the same way, or on a background thread or with readabilityHandler, since a full stderr pipe deadlocks too.
