From 056fa5ff76b111bb4516a5a53b917e2df31434ec Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Thu, 6 Aug 2026 11:50:47 -0700 Subject: [PATCH] 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. --- Modules/RSWeb/Sources/RSWeb/Downloader.swift | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Modules/RSWeb/Sources/RSWeb/Downloader.swift b/Modules/RSWeb/Sources/RSWeb/Downloader.swift index a64123356..7a9a74c7e 100755 --- a/Modules/RSWeb/Sources/RSWeb/Downloader.swift +++ b/Modules/RSWeb/Sources/RSWeb/Downloader.swift @@ -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)")