In our fallback, buffered implementation, we did not use a task cancellation handler so were not proactively cancelling the URLSession task when the Swift concurrency task was cancelled. Additionally, while we did have a task cancellation handler in the streaming implementation, so the URLSession task would be cancelled, we were not actively checking for task cancellation as often as we could.
Modifications
Added more cooperative task cancellation.
Added tests for both implementations that when the parent task for the client request is cancelled that we get something sensible. Note that in some cases, the request will succeed. In the cases where the request fails, it will surface as a ClientError to the user where the underlyingError is either Swift.CancellationError or URLError with code == .cancelled.
Result
More cooperative task and URLSession task cancellation and more thorough tests.
Motivation
In our fallback, buffered implementation, we did not use a task cancellation handler so were not proactively cancelling the URLSession task when the Swift concurrency task was cancelled. Additionally, while we did have a task cancellation handler in the streaming implementation, so the URLSession task would be cancelled, we were not actively checking for task cancellation as often as we could.
Modifications
ClientError
to the user where theunderlyingError
is eitherSwift.CancellationError
orURLError
withcode == .cancelled
.Result
More cooperative task and URLSession task cancellation and more thorough tests.
Test Plan
Added unit tests.