From 97156bf4180c78a68e493eecdd1df0f82b8eaed7 Mon Sep 17 00:00:00 2001 From: Vasil Erema <6029382+VasilErema@users.noreply.github.com> Date: Tue, 1 Oct 2024 18:21:09 +0200 Subject: [PATCH] Replace recursive call with while loop to prevent stack overflow. --- .../Attachments/AttachmentDownloadRetryRunner.swift | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Signal/Attachments/AttachmentDownloadRetryRunner.swift b/Signal/Attachments/AttachmentDownloadRetryRunner.swift index b2dff1f8354..2f3cf985c7f 100644 --- a/Signal/Attachments/AttachmentDownloadRetryRunner.swift +++ b/Signal/Attachments/AttachmentDownloadRetryRunner.swift @@ -81,10 +81,10 @@ public class AttachmentDownloadRetryRunner { } private func run() async { - do { - self.isRunning = true - defer { self.isRunning = false } - + self.isRunning = true + defer { self.isRunning = false } + // Run while there is a next timestamp. + while true { let nextTimestamp = db.read { tx in return try? self.attachmentDownloadStore.nextRetryTimestamp(tx: tx.asV2Read) } @@ -102,9 +102,6 @@ public class AttachmentDownloadRetryRunner { // Kick the tires to start any downloads. attachmentDownloadManager.beginDownloadingIfNecessary() } - - // Run again to wait for the next timestamp. - await self.run() } }