mirror of
https://github.com/yattee/yattee.git
synced 2026-07-20 14:22:02 +00:00
Fix download completion crash from stale array index across await
completeMultiFileDownload captured an index via firstIndex, then awaited a detached file-size calculation. Another concurrently-completing download could mutate activeDownloads during that suspension, leaving the index stale and crashing in Array.remove(at:) with an out-of-bounds index. Remove the download by identity instead. Fixes a SIGTRAP seen in TestFlight build 261 (5 reports).
This commit is contained in:
@@ -705,8 +705,11 @@ extension DownloadManager {
|
||||
download.totalBytes = totalBytes
|
||||
download.downloadedBytes = totalBytes
|
||||
|
||||
// Move to completed
|
||||
activeDownloads.remove(at: index)
|
||||
// Move to completed. Remove by identity rather than the captured `index`:
|
||||
// the `await` above is a suspension point during which another completing
|
||||
// download may have mutated `activeDownloads`, leaving `index` stale and
|
||||
// making `remove(at:)` crash with an out-of-bounds index.
|
||||
activeDownloads.removeAll { $0.id == downloadID }
|
||||
completedDownloads.insert(download, at: 0)
|
||||
|
||||
// Update cached Sets
|
||||
|
||||
Reference in New Issue
Block a user