Skip to content

Reject writes after StandardInputWriter finishes with a clear error#311

Merged
iCharlesHu merged 1 commit into
swiftlang:mainfrom
iCharlesHu:charles/standard-input-writer-error
Jun 12, 2026
Merged

Reject writes after StandardInputWriter finishes with a clear error#311
iCharlesHu merged 1 commit into
swiftlang:mainfrom
iCharlesHu:charles/standard-input-writer-error

Conversation

@iCharlesHu

Copy link
Copy Markdown
Contributor

Retaining the StandardInputWriter beyond the run body closure no longer hangs, but using the writer after that point failed with a cryptic 'Bad file descriptor', and nothing flagged the misuse. Track whether the writer has finished and throw a descriptive SubprocessError on a subsequent write, instead of writing to a closed and possibly recycled file descriptor. finish() is now explicitly idempotent.

Document the writer's lifetime contract on StandardInputWriter and Execution.standardInputWriter: it is valid only within the body closure, run calls finish() automatically when the body returns, and awaiting the child's full output without finishing first can deadlock.

Resolves: #186

Retaining the StandardInputWriter beyond the run body closure no longer hangs, but using the writer after that point failed with a cryptic 'Bad file descriptor', and nothing flagged the misuse. Track whether the writer has finished and throw a descriptive SubprocessError on a subsequent write, instead of writing to a closed and possibly recycled file descriptor. finish() is now explicitly idempotent.

Document the writer's lifetime contract on StandardInputWriter and Execution.standardInputWriter: it is valid only within the body closure, run calls finish() automatically when the body returns, and awaiting the child's full output without finishing first can deadlock.
@iCharlesHu iCharlesHu requested a review from jakepetroules June 11, 2026 19:51
@iCharlesHu iCharlesHu merged commit 13904bc into swiftlang:main Jun 12, 2026
46 checks passed
@iCharlesHu iCharlesHu deleted the charles/standard-input-writer-error branch June 12, 2026 00:41
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.

Retaining the StandardInputWriter prevents write from happening / being flushed

2 participants