NSURLSessionTask's taskIdentifier isn't always unique.

Originator:padraig.kennedy
Number:rdar://17029580 Date Originated:25 May 2014
Status:Fixed in iOS8 Resolved:
Product:iOS SDK Product Version:7.1.1
Classification:Serious Bug Reproducible:Always
 
Summary:
taskIdentifiers on an NSURLSessionDataTask should be unique per NSURLSession, as the documentation states. The attached projects demonstrates an issue where tasks that are created concurrently can end up with the same taskIdentifier.

Steps to Reproduce:
1. Dispatch 100 data tasks on the default priority queue.
2. Monitor the taskIdentifiers returned by the task.
3. Observe that they are occasionally the same — likely, since the queue is concurrent, this is when two tasks end up getting created on different threads around the same time.

Expected Results:
Task Identifiers should be unique per NSURLSession, as the documentation states.

Actual Results:
Task Identifiers are not always unique. The popular AFNetworking framework depends on this uniqueness, and can end up calling incorrect completionHandlers.

Version:
iOS 7.1.1

Notes:
I have attached an example project which recreates the issue reliably.

Configuration:
Recreates easiest on the simulator, but I have done it on the device too.

Attachments:
'taskIdentifierNope.zip' was successfully uploaded.

Comments

Through an rough testing, I found that URL Session configured with background configuration is not affected by this bug even on iOS 7.1.1.

It looks like the Background URL Session daemon takes good care of creating tasks in serial order.


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!