From ec5ac944c499ca34baee03ee36b970857066d8a8 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Mon, 11 May 2026 22:50:16 +0200 Subject: [PATCH] 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). --- Yattee/Services/Downloads/DownloadManager+Execution.swift | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Yattee/Services/Downloads/DownloadManager+Execution.swift b/Yattee/Services/Downloads/DownloadManager+Execution.swift index 104e3498..d908b2f7 100644 --- a/Yattee/Services/Downloads/DownloadManager+Execution.swift +++ b/Yattee/Services/Downloads/DownloadManager+Execution.swift @@ -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