提交 40aad9c4 编写于 作者: C Christian Noon

Updated session to no longer resume task for cancelled request

A stress test built into AlamofireImage identified a race condition when cancelling a request. When the request is manually cancelled, it will automatically call request.finish() if the task has not yet been created. This will run the response serializer and eventually call the response handler’s completion closure. While this is the exact behavior we want, there is an extremely small chance that the task will be created immediately after that check. When this happens, the previous code would resume and immediately cancel the request which would result in the SessionDelegate receiving the call that the task was completed. This would then process the next response serializer which would end up calling the response handler’s completion closure a second time.
上级 052c2c23
......@@ -932,10 +932,8 @@ open class Session {
task.suspend()
rootQueue.async { request.didSuspendTask(task) }
case (_, .cancelled):
// Resume to ensure metrics are gathered.
task.resume()
task.cancel()
rootQueue.async { request.didCancelTask(task) }
// Do nothing
break
case (_, .finished):
// Do nothing
break
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册