From 70ec1bfe5bd4933fa2e58e689580dfab946ea7d9 Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Tue, 15 Jul 2025 11:59:18 +0200 Subject: [PATCH] Add log messages for when a process gets terminated because the task is cancelled I hope this makes it easier to spot why a `swift build` launched for target preparation does not get terminated when the preparation task is cancelled, as we saw in https://ci-external.swift.org/job/sourcekit-lsp-PR-windows/3089/. --- Sources/TSCExtensions/Process+Run.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/TSCExtensions/Process+Run.swift b/Sources/TSCExtensions/Process+Run.swift index 47fbca764..76c9bc91c 100644 --- a/Sources/TSCExtensions/Process+Run.swift +++ b/Sources/TSCExtensions/Process+Run.swift @@ -38,11 +38,13 @@ extension Process { } return try await waitUntilExit() } onCancel: { + logger.debug("Terminating process using SIGINT because task was cancelled: \(self.arguments)") signal(SIGINT) Task { // Give the process 2 seconds to react to a SIGINT. If that doesn't work, terminate the process. try await Task.sleep(for: .seconds(2)) if !hasExited.value { + logger.debug("Terminating process using SIGKILL because it did not honor SIGINT: \(self.arguments)") // TODO: We should also terminate all child processes (https://github.com/swiftlang/sourcekit-lsp/issues/2080) #if os(Windows) // Windows does not define SIGKILL. Process.signal sends a `terminate` to the underlying Foundation process