Skip to content

Commit 29c0c5a

Browse files
authored
Do not try to interrupt/terminate a process if it isn't running (#5675)
Calling these on a process that isn't currently running results in ``` 'NSInvalidArgumentException', reason: '*** -[NSConcreteTask terminate]: task not launched' ``` so we should check first. rdar://96964401 (cherry picked from commit 0464fcf)
1 parent 5e22621 commit 29c0c5a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Sources/Basics/Cancellator.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,21 @@ extension TSCBasic.Process {
145145
#if !os(iOS) && !os(watchOS) && !os(tvOS)
146146
extension Foundation.Process {
147147
fileprivate func terminate(timeout: DispatchTime) {
148+
guard self.isRunning else {
149+
return
150+
}
151+
148152
// send graceful shutdown signal (SIGINT)
149153
self.interrupt()
150154

151155
// start a thread to see if we need to terminate more forcibly
152156
let forceKillSemaphore = DispatchSemaphore(value: 0)
153157
let forceKillThread = TSCBasic.Thread {
154158
if case .timedOut = forceKillSemaphore.wait(timeout: timeout) {
159+
guard self.isRunning else {
160+
return
161+
}
162+
155163
// force kill (SIGTERM)
156164
self.terminate()
157165
}

0 commit comments

Comments
 (0)