Skip to content

Cancel a stalled standard-input writer when the child process exits#306

Merged
iCharlesHu merged 1 commit into
swiftlang:mainfrom
iCharlesHu:charles/cancellable-input
Jun 10, 2026
Merged

Cancel a stalled standard-input writer when the child process exits#306
iCharlesHu merged 1 commit into
swiftlang:mainfrom
iCharlesHu:charles/cancellable-input

Conversation

@iCharlesHu

Copy link
Copy Markdown
Contributor

When run() feeds standard input from a source that can stall and the child process exits before consuming that input, run() could hang indefinitely. The input-writing task was parked awaiting its source rather than blocked inside a pipe write, so the existing cancelAsyncIO path (which only unblocks in-flight pipe I/O) could not release it, and the I/O task group never finished draining. Spawn a waitForProcessTermination waiter alongside the input-writing task that cancels the I/O group once the child exits.

Also add edge-case coverage for process I/O and AsyncIO, ported from swift-async-process and swift-nio and replace FileDescriptor.close with _safelyClosed.

@iCharlesHu iCharlesHu requested a review from jakepetroules June 9, 2026 23:18
Comment thread Tests/SubprocessTests/IntegrationTests.swift Outdated
When run() feeds standard input from a source that can stall and the child process exits before consuming that input, run() could hang indefinitely. The input-writing task was parked awaiting its source rather than blocked inside a pipe write, so the existing cancelAsyncIO path (which only unblocks in-flight pipe I/O) could not release it, and the I/O task group never finished draining. Spawn a waitForProcessTermination waiter alongside the input-writing task that cancels the I/O group once the child exits.

Also add edge-case coverage for process I/O and AsyncIO, ported from swift-async-process and swift-nio and replace FileDescriptor.close with _safelyClosed.
@iCharlesHu iCharlesHu force-pushed the charles/cancellable-input branch from ee4615f to 7815dfe Compare June 10, 2026 00:05
@iCharlesHu iCharlesHu merged commit 039f29c into swiftlang:main Jun 10, 2026
46 checks passed
@iCharlesHu iCharlesHu deleted the charles/cancellable-input branch June 10, 2026 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants