diff --git a/libsession/src/main/java/org/session/libsession/messaging/jobs/RetrieveProfileAvatarJob.kt b/libsession/src/main/java/org/session/libsession/messaging/jobs/RetrieveProfileAvatarJob.kt index d4296a82d7..9ca2534f66 100644 --- a/libsession/src/main/java/org/session/libsession/messaging/jobs/RetrieveProfileAvatarJob.kt +++ b/libsession/src/main/java/org/session/libsession/messaging/jobs/RetrieveProfileAvatarJob.kt @@ -17,12 +17,13 @@ import java.io.FileInputStream import java.io.FileOutputStream import java.io.InputStream import java.security.SecureRandom +import java.util.concurrent.ConcurrentSkipListSet class RetrieveProfileAvatarJob(private val profileAvatar: String?, val recipientAddress: Address): Job { override var delegate: JobDelegate? = null override var id: String? = null override var failureCount: Int = 0 - override val maxFailureCount: Int = 0 + override val maxFailureCount: Int = 3 companion object { val TAG = RetrieveProfileAvatarJob::class.simpleName @@ -31,10 +32,14 @@ class RetrieveProfileAvatarJob(private val profileAvatar: String?, val recipient // Keys used for database storage private const val PROFILE_AVATAR_KEY = "profileAvatar" private const val RECEIPIENT_ADDRESS_KEY = "recipient" + + val errorUrls = ConcurrentSkipListSet() + } override suspend fun execute(dispatcherName: String) { val delegate = delegate ?: return + if (profileAvatar in errorUrls) return delegate.handleJobFailed(this, dispatcherName, Exception("Profile URL 404'd this app instance")) val context = MessagingModuleConfiguration.shared.context val storage = MessagingModuleConfiguration.shared.storage val recipient = Recipient.from(context, recipientAddress, true) @@ -85,7 +90,10 @@ class RetrieveProfileAvatarJob(private val profileAvatar: String?, val recipient storage.setProfileAvatar(recipient, profileAvatar) } catch (e: Exception) { Log.e("Loki", "Failed to download profile avatar", e) - return delegate.handleJobFailedPermanently(this, dispatcherName, e) + if (failureCount + 1 >= maxFailureCount) { + errorUrls += profileAvatar + } + return delegate.handleJobFailed(this, dispatcherName, e) } finally { downloadDestination.delete() } diff --git a/libsession/src/main/java/org/session/libsession/snode/OnionRequestAPI.kt b/libsession/src/main/java/org/session/libsession/snode/OnionRequestAPI.kt index f3b2c5f93f..8851dfc2b3 100644 --- a/libsession/src/main/java/org/session/libsession/snode/OnionRequestAPI.kt +++ b/libsession/src/main/java/org/session/libsession/snode/OnionRequestAPI.kt @@ -419,6 +419,8 @@ object OnionRequestAPI { Log.d("Loki","Destination server returned ${exception.statusCode}") } else if (message == "Loki Server error") { Log.d("Loki", "message was $message") + } else if (exception.statusCode == 404) { + // 404 is probably file server missing a file, don't rebuild path or mark a snode as bad here } else { // Only drop snode/path if not receiving above two exception cases handleUnspecificError() }