Skip to content

Use of Execution and teardown sequences race with process termination #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions Sources/Subprocess/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,30 +74,29 @@ public struct Configuration: Sendable {
let pid = spawnResults.execution.processIdentifier

var spawnResultBox: SpawnResult?? = consume spawnResults
var _spawnResult = spawnResultBox!.take()!

return try await withAsyncTaskCleanupHandler {
var _spawnResult = spawnResultBox!.take()!
let processIdentifier = _spawnResult.execution.processIdentifier

let result = try await withAsyncTaskCleanupHandler {
let inputIO = _spawnResult.inputWriteEnd()
let outputIO = _spawnResult.outputReadEnd()
let errorIO = _spawnResult.errorReadEnd()
let processIdentifier = _spawnResult.execution.processIdentifier

async let terminationStatus = try monitorProcessTermination(
forProcessWithIdentifier: processIdentifier
)
// Body runs in the same isolation
let result = try await body(_spawnResult.execution, inputIO, outputIO, errorIO)
return ExecutionResult(
terminationStatus: try await terminationStatus,
value: result
)
return try await body(_spawnResult.execution, inputIO, outputIO, errorIO)
} onCleanup: {
// Attempt to terminate the child process
await Execution.runTeardownSequence(
self.platformOptions.teardownSequence,
on: pid
)
}

return ExecutionResult(
terminationStatus: try await monitorProcessTermination(forProcessWithIdentifier: processIdentifier),
value: result
)
}
}

Expand Down
Loading