Skip to content

Commit c462c71

Browse files
committed
Capture available data early
The availableData object should be captured in the event handler. If you delay reading the data to the synchronization queue, the socket may be closed already (leading to an ObjC exception you can't catch).
1 parent 95a473b commit c462c71

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Sources/ShellOut.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,16 +367,16 @@ private extension Process {
367367

368368
#if !os(Linux)
369369
outputPipe.fileHandleForReading.readabilityHandler = { handler in
370+
let data = handler.availableData
370371
outputQueue.async {
371-
let data = handler.availableData
372372
outputData.append(data)
373373
outputHandle?.write(data)
374374
}
375375
}
376376

377377
errorPipe.fileHandleForReading.readabilityHandler = { handler in
378+
let data = handler.availableData
378379
outputQueue.async {
379-
let data = handler.availableData
380380
errorData.append(data)
381381
errorHandle?.write(data)
382382
}

0 commit comments

Comments
 (0)