You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG][swift6] urlsession: cancelling while an interceptor completes asynchronously still sends the request #25848
#25188 (fixing #25182) re-checks Task.isCancelled after execute(completion:) returns. That only covers interceptors whose intercept completes synchronously. If OpenAPIInterceptor.intercept completes asynchronously (e.g. after a token refresh), RequestTask holds no data task yet, so neither onCancel nor the re-check has anything to cancel. The data task is created and resumed afterwards and the request is sent. The same happens when a cancel arrives while the retry interceptor is working (e.g. refreshing a token after a 401) before .retry re-executes the request.
The gap was acknowledged in #25188 (comment) and left for a follow-up.
Actual: the request is sent although the Task was cancelled. Expected: the request is not sent and no retry is attempted.
Any swift6 config with the urlsession library, e.g. bin/configs/swift6-asyncAwaitLibrary.yaml. The alamofire library is not affected: its request exists as soon as execute(completion:) returns.
Steps to reproduce
Set an OpenAPIInterceptor whose intercept calls completion from a Task after a delay.
Call try await builder.execute() from a Task.
Cancel the Task while the interceptor is pending.
Suggest a fix
RequestTask should remember a cancel() for the current execution and cancel a data task that is set afterwards, while a fresh public execute(completion:) clears it, because RxSwift/Combine wrappers call cancel() on disposal and re-execute the same builder. PR follows.
Activity