Skip to content

[IO_URING] Keep the completion of failed IORing operations - #401

Merged
FranzBusch merged 2 commits into
mainfrom
fb-iouring-completion-error
Oct 6, 2026
Merged

FranzBusch merged 2 commits into
mainfrom
fb-iouring-completion-error

Conversation

@FranzBusch

Copy link
Copy Markdown
Member

When an operation failed, the blocking consume methods dropped its completion and only reported the Errno. The caller could not tell which request failed, since the context was lost. This breaks any user that matches completions to requests.

This PR makes blockingConsumeCompletions pass the completion of a failed operation together with its error. Errors of the ring itself, such as .timeout, are still passed without a completion. Additionally, blockingConsumeCompletion(timeout:) now returns the completion of a failed operation instead of throwing. It only throws errors of the ring itself.

I also added Completion.error, which is nil on success and the decoded Errno otherwise to make it easy to get to the error of a completion.

Fixes #364
Fixes #395

@FranzBusch
FranzBusch requested review from jrflat and removed request for glessard and lorentey October 5, 2026 18:58
When an operation failed, the blocking consume methods dropped its completion and only reported the `Errno`. The caller could not tell which request failed, since the `context` was lost. This breaks any user that matches completions to requests.

This PR makes `blockingConsumeCompletions` pass the completion of a failed operation together with its error. Errors of the ring itself, such as `.timeout`, are still passed without a completion. Additionally, `blockingConsumeCompletion(timeout:)` now returns the completion of a failed operation instead of throwing. It only throws errors of the ring itself.

I also added `Completion.error`, which is `nil` on success and the decoded `Errno` otherwise to make it easy to get to the error of a completion.

Fixes #364
Fixes #395
@FranzBusch
FranzBusch force-pushed the fb-iouring-completion-error branch from 2de2728 to cbf57d4 Compare October 5, 2026 18:59

@jrflat jrflat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I think it's a good behavior change but we should call it out in a release note for the next minor bump.

Comment thread Sources/System/IORing/IORequest.swift
/// (or forever if not specified). For each completed operation found, `consumer` is called to handle
/// processing it.
///
/// `consumer` receives a completion, an error, and whether consuming is done:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a similar note to submitPreparedRequestsAndConsumeCompletions since this updates its behavior, too.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Updated and added a test

@FranzBusch
FranzBusch merged commit 486d48c into main Oct 6, 2026
66 checks passed
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.

[IOU_RING] Failed completions lose their user_data IORing: blockingConsumeCompletions() drops context on error

2 participants