mzeeshanid / MZDownloadManager

This download manager uses NSURLSession api to download files. It can download multiple files at a time. It can download large files if app is in background. It can resume downloads if app was quit.
BSD 3-Clause "New" or "Revised" License
1.12k stars 238 forks source link

Two Simultaneous Download Tasks Results in Crash #34

Closed danielmhanover closed 7 years ago

danielmhanover commented 7 years ago

There seems to be an array index out of bounds error at line 222 in MZDownloadManager.swift here:

self.downloadingArray[index] = downloadModel

It seems that when the first download completes, it is removed from the downloadingArray, but the second download's index does not change from 1 to 0. We could resolve this by changing downloadingArray to a dictionary, and changing the downloadModel's index to some randomly generated string. Thoughts?

professionalsna commented 7 years ago

same error with me too, while adding multiple downloads in array. please help

professionalsna commented 7 years ago

or Can we limit downloader to download one by one at a time after placing it in queue, currently 3 items starts downloading.

mzeeshanid commented 7 years ago

Can you write down some steps how we can reproduce it?

professionalsna commented 7 years ago

loop through available downloads array and add them into download manager. few files are is very small size so they are downloaded very quickly while still we are in loop (addDownloadTask). this adding makes crash on
self.downloadingArray[index] = downloadModel

because downloaded files are removed from array

to reproduce you can use the following

for down in availableDownloadsArray { let fileURL : down as NSString let fileName : NSString = fileURL.lastPathComponent as NSString mzDownloadingViewObj?.downloadManager.addDownloadTask(fileName as String, fileURL: fileURL.addingPercentEscapes(using: String.Encoding.utf8.rawValue)!, destinationPath: myDownloadPath) }

digvijay96 commented 6 years ago

Getting the same crash when downloading two files at line 209 MZDownloadManager.URLSession(_:downloadTask:didWriteData:totalBytesWritten:totalBytesExpectedToWrite:)