Automattic / Automattic/wordpress-rs

A Swift Task cancelled before the URLSession task is registered runs the request to completion

Open
#1,518 0 comments 0 reactions 0 assignees View on GitHub
Bug Error Handling Swift
Dominant language
Rust
Stars
36
Forks
5
Avg merge
17h 30m
Merged PRs (30d)
43

Description

> Split out from Automattic/wordpress-rs#1497 — *Swift executor URLSession error audit*. Section E — Cancellation gaps.
>
> File references are to `native/swift/Sources/wordpress-api/SafeRequestExecutor.swift` unless noted; `:NNN` line numbers were verified against `fix/converge-executor-error-classification`.

**Severity: medium.** In both `perform` implementations, `withTaskCancellationHandler`'s `onCancel` calls `cancellation.cancel()`, which nils a still-unset `_task`; `TaskCancellation` has no cancelled latch, and `withTaskCancellationHandler` invokes `onCancel` immediately when the surrounding Task is already cancelled — before the continuation body creates the URLSession task. A pre-cancelled or racing cancellation therefore cancels nothing: the request executes fully (a cancelled POST/DELETE still sends the mutation) and the caller receives success instead of `CancellationError`. Fix: latch `cancel()` and cancel any task assigned after the fact, and/or check `Task.isCancelled` before resuming.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in native/swift/Sources/wordpress-api/SafeRequestExecutor.swift, focusing on both perform implementations and TaskCancellation. Trace pre-cancelled and racing cancellation through the continuation and URLSession task registration; done means cancellation prevents the request from completing and the caller receives CancellationError.

Written by the indexing model from the issue text.

Assessment

Tech stack
swift
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.