Skip to content

HTTPBodyOutputStream should handle multiple terminal events#95

Merged
guoye-zhang merged 1 commit into
apple:mainfrom
budde:handle-close-precondition
Jun 23, 2026
Merged

HTTPBodyOutputStream should handle multiple terminal events#95
guoye-zhang merged 1 commit into
apple:mainfrom
budde:handle-close-precondition

Conversation

@budde

@budde budde commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Motivation

#94 added a new cancel() path used by the URLSession delegate to clean up HTTPBodyOutputStream resources on errors received by the delegate but not forwarded to the output stream.

As detailed in apple/swift-openapi-generator#918 though, we need to refactor the existing code so that late-arriving terminal events (endEncountered, wroteFinalChunk and errorOccurred) from the CFStream delegate and the writer tasks do not trigger a fatal preconditionFailure() if an error was already forwarded by the URLSession delegate via cancel().

Modifications

Emit a debug() log and return an action of .none if the stream is in a closed state when handling an endEncountered, wroteFinalChunk or errorOccurred event.

Result

There is no longer a race condition that can lead to a fatal preconditionFailure.

Test Plan

Added unit tests to cover specific even handling changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants