NSURLSession's getAllTasksWithCompletionHandler and getTasksWithCompletionHandler methods don't include suspended tasks unless they've been previously resumed.

Originator:craig
Number:rdar://28608776 Date Originated:04-Oct-2016 03:08 PM
Status:Open Resolved:
Product:iOS Product Version:10.0.1
Classification:Serious Bug Reproducible:Always
 
Summary:
The documentation for NSURLSession::getTasksWithCompletionHandler: states:

“The returned arrays contain any tasks that you have created within the session, not including any tasks that have been invalidated after completing, failing, or being cancelled.”

So I’d expect suspended tasks to feature in those arrays (the documentation for the newer getAllTasksWithCompletionHandler: is empty but I’d expect the same).

This is not always the case, however. Suspended tasks do appear if they were at one point started via a “resume” message before being subsequently suspended, but non-started tasks which naturally start in the suspended state do not appear – presenting a clear inconsistency.

Steps to Reproduce:
See the example project (attached, or at https://github.com/Bipsync/ios-nsurlsession-getsuspendedtasks).

- Create a NSURLSessionTask in a NSURLSession
- Observe that its state is NSURLSessionTaskSuspended
- Call either getTasksWithCompletionHandler or getAllTasksWithCompletionHandler

Expected Results:
As the task is not complete, failing, or being cancelled, it should be present in the array.

Actual Results:
The task is not present.

Regression:
Unsure

Notes:
I think it would be better if this was addressed in line with the documentation (i.e. rather than excluding suspended tasks in all cases, suspended tasks should always feature in the results irrespective of whether they were ever resumed). Personally, I often find the need to decouple the resumption of tasks from the creation code, so being able to find suspended tasks after their creation is a crucial requirement.

Example project is at https://github.com/Bipsync/ios-nsurlsession-getsuspendedtasks

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!