Skip to content

Commit f32a63b

Browse files
authored
Fix a race which could allow Swift tasks to be reported as failed instead of cancelled (swiftlang#367)
Ensure that if the process for a Job is never reported as started, we report it as cancelled rather than failed. This is consistent with C compiles and other task types. rdar://138056158
1 parent f67ead1 commit f32a63b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

Sources/SWBTaskExecution/TaskActions/SwiftDriverJobTaskAction.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,14 @@ public final class SwiftDriverJobTaskAction: TaskAction, BuildValueValidatingTas
419419
private var pid = llbuild_pid_t.invalid
420420

421421
var executionError: String?
422-
var commandResult: CommandResult?
422+
private var processStarted = false
423+
private var _commandResult: CommandResult?
424+
var commandResult: CommandResult? {
425+
guard processStarted else {
426+
return .cancelled
427+
}
428+
return _commandResult
429+
}
423430

424431
init(plannedBuild: LibSwiftDriver.PlannedBuild?, driverJob: LibSwiftDriver.PlannedBuild.PlannedSwiftDriverJob, arguments: [String], environment: [String : String], outputDelegate: any TaskOutputDelegate) {
425432
self.plannedBuild = plannedBuild
@@ -430,6 +437,7 @@ public final class SwiftDriverJobTaskAction: TaskAction, BuildValueValidatingTas
430437
}
431438

432439
func processStarted(pid: llbuild_pid_t?) {
440+
processStarted = true
433441
do {
434442
guard let pid else {
435443
// `pid` is only optional because the Windows implementation of llbuild's pid_t type is optional. This should never be nil on other platforms
@@ -465,7 +473,7 @@ public final class SwiftDriverJobTaskAction: TaskAction, BuildValueValidatingTas
465473
if outputDelegate.result == nil {
466474
outputDelegate.updateResult(TaskResult(result))
467475
}
468-
self.commandResult = result.result
476+
self._commandResult = result.result
469477
do {
470478
try plannedBuild?.jobFinished(job: driverJob, arguments: arguments, pid: pid.pid, environment: environment, exitStatus: .exit(result.exitStatus), output: output)
471479
} catch {

0 commit comments

Comments
 (0)