Background URLSessionDownloadTask bug

Originator:an00na
Number:rdar://31505061 Date Originated:07-Apr-2017 01:26 PM
Status:Open Resolved:
Product:iOS + SDK Product Version:10.3
Classification:Serious Bug Reproducible:Always
 
Area:
Foundation

Summary:
If the 1st background URLSessionDownloadTask resuming complete download successfully everything is fine.

However, if the 1st trial is interrupted, say because the app is skilled again, the following attempts to resume the download can still succeed, but the `location` argument passed in urlSession(_:downloadTask:didFinishDownloadingTo:) is wrong which causes the downloaded file cannot be correctly used. Notice that the downloaded file is there in the cache dir, just we cannot get its location in the callback.

Steps to Reproduce:
1. On your testing device ,turn on system Settings > Developer > Network Link Conditioner with Edge profile, in case your network is too good to leave you any time to do the operations.

2. Launch sample app from Xcode.
3. Kill the app by Stop in Xcode after you see some % download progress in console logs.
4. Relaunch sample app from Xcode.
5. Wait until the download to complete.
6. Read the console log to see the good `location`.

7. Repeat 2~4.
8. Kill the app again by Stop in Xcode after you see more % download progress in console logs.
9. Repeat 4~5.
10. Read the console log to see the wrong `location` and correct url.

Code: https://cloudup.com/cC6YM6SXRDf

Comments

Reupload the project

Hi, your project demo code is not available any more, could you please reupload the code? I'm having the same issue.


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!