Skip to content

feat(swift): transactions run withTaskCancellationHandler [WPB-27117]#2340

Open
SimonThormeyer wants to merge 16 commits into
mainfrom
simon/feat/swift-cancellation
Open

feat(swift): transactions run withTaskCancellationHandler [WPB-27117]#2340
SimonThormeyer wants to merge 16 commits into
mainfrom
simon/feat/swift-cancellation

Conversation

@SimonThormeyer

@SimonThormeyer SimonThormeyer commented Jul 17, 2026

Copy link
Copy Markdown
Member

Make core crypto ffi transactions cancellable and run the ffi transaction withTaskCancellationHandler in the wrapper.

@SimonThormeyer
SimonThormeyer force-pushed the simon/feat/swift-cancellation branch 2 times, most recently from 1e75636 to 7bfd6a8 Compare July 17, 2026 12:06
@SimonThormeyer SimonThormeyer changed the title Simon/feat/swift cancellation feat(swift): transactions run withTaskCancellationHandler [WPB-27117] Jul 17, 2026
@SimonThormeyer SimonThormeyer changed the title feat(swift): transactions run withTaskCancellationHandler [WPB-27117] feat(swift): transactions run withTaskCancellationHandler [WPB-27117] Jul 17, 2026
@SimonThormeyer
SimonThormeyer marked this pull request as ready for review July 17, 2026 12:08
@SimonThormeyer
SimonThormeyer requested a review from a team July 17, 2026 12:08
@SimonThormeyer
SimonThormeyer force-pushed the simon/feat/swift-cancellation branch from 7bfd6a8 to 8597d5a Compare July 17, 2026 12:14
This allows the `CoreCryptoFfi` struct to store the current cancellation
token and race an mls transport future against its cancellation.
This future is created from the cancellation token and will resolve when
someone calls `.cancel()` on the token.
…d `MlsTransportShim`

...And make `MlsTransportShim` race against token cancellation in
`send_commit_bundle()`.
We need `CoreCryptoFfi` to be aware if it has a `PkiEnvironment` so that
it can use the cancellation slot to store the token in when starting a
transaction.
Upon creation of the transaction, the PKI environment also receives the
cancellation slot which gets filled with the cancellation token for the
duration of the transaction.

The PKI env hooks, which may be as long-running as mls transport
callbacks, will then also race against cancellation of the token.
And use it to gate all items added in this PR.
Also, use an extra target directory for the swift uniffi binary to avoid
it being confused with the kotlin one.
@SimonThormeyer
SimonThormeyer force-pushed the simon/feat/swift-cancellation branch from 9f7bb84 to c65e405 Compare July 17, 2026 12:29
We're using an entirely seperate flow now when generating on macOS
@SimonThormeyer
SimonThormeyer force-pushed the simon/feat/swift-cancellation branch from 78a095f to c19624b Compare July 17, 2026 12:38

// Assert that cancellation is triggered without waiting for either callback result.
do {
try await transactionTask.value

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We have a XCTAssertThrowsErrorAsync helper you can use here.

@SimonThormeyer SimonThormeyer Jul 17, 2026

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.

When trying to use it like this

        let expectedError = CancellationError()
        // Assert that cancellation is triggered without waiting for either callback result.
        await XCTAssertThrowsErrorAsync(
            expectedError,
            when: {
                try await transactionTask.value
            }
        )

I get
Instance method 'XCTAssertThrowsErrorAsync(_:when:_:file:line:)' requires that 'CancellationError' conform to 'Equatable'

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