rpc: ensure worker is killed if it hangs on shutdown

This commit is contained in:
Peter Steinberger
2025-12-09 03:04:00 +00:00
parent 2177df51a8
commit 4eb71bcd14

View File

@@ -1,4 +1,5 @@
import Foundation
import Darwin
import OSLog
struct ControlRequestParams: @unchecked Sendable {
@@ -242,6 +243,12 @@ actor AgentRPC {
self.stdoutHandle?.readabilityHandler = nil
let proc = self.process
proc?.terminate()
if let proc, proc.isRunning {
try? await Task.sleep(nanoseconds: 700_000_000)
if proc.isRunning {
kill(proc.processIdentifier, SIGKILL)
}
}
proc?.waitUntilExit()
self.process = nil
self.stdinHandle = nil