Release a URL's download callbacks before calling them, so a callback that starts a new download of the same URL isn't silently dropped.

This commit is contained in:
Brent Simmons committed 2026-08-06 11:50:47 -07:00
1 parent e2fe6a1798
commit 056fa5ff76
1 file changed
+3 -4
+3 -4
View File
@@ -133,16 +133,15 @@ private extension Downloader {
func callAndReleaseCallbacks(_ url: URL, _ data: Data? = nil, _ response: URLResponse? = nil, _ error: Error? = nil) {
assert(Thread.isMainThread)
defer {
callbacks[url] = nil
}
guard let callbacksForURL = callbacks[url] else {
assertionFailure("Downloader: downloaded URL \(url) but no callbacks found")
Self.logger.fault("Downloader: downloaded URL \(url) but no callbacks found")
return
}
// Release before calling — a callback may start a new download of the same URL.
callbacks[url] = nil
let count = callbacksForURL.count
if count == 1 {
Self.logger.debug("Downloader: calling 1 callback for URL \(url)")