Skip to content

Commit b07ad92

Browse files
committed
Set isRunning of Process to false before calling the termination handler
Otherwise, we end up in a race condition where `isRunning` might still be `true` when accessed from inside the `terminationHandler`. If this is the case, accessing `terminationReason` or `terminationStatus` inside the termination handler crashes because their precondition that the task has finished are not satisfied. Fixes rdar://78035044
1 parent 2232811 commit b07ad92

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Sources/Foundation/Process.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -830,6 +830,9 @@ open class Process: NSObject {
830830
process._terminationReason = .exit
831831
}
832832

833+
// Set the running flag to false
834+
process.isRunning = false
835+
833836
// If a termination handler has been set, invoke it on a background thread
834837

835838
if let terminationHandler = process.terminationHandler {
@@ -839,9 +842,6 @@ open class Process: NSObject {
839842
thread.start()
840843
}
841844

842-
// Set the running flag to false
843-
process.isRunning = false
844-
845845
// Invalidate the source and wake up the run loop, if it's available
846846

847847
CFRunLoopSourceInvalidate(process.runLoopSource)

0 commit comments

Comments
 (0)