Fix crash and subsequent retry after upload to archive fails length check.

This commit is contained in:
Cody Henthorne
2026-04-29 12:59:36 -04:00
committed by Greyson Parrelli
parent bb261a3d85
commit e11f7225d3
2 changed files with 19 additions and 0 deletions
@@ -12,6 +12,7 @@ import org.signal.core.util.Util
import org.signal.core.util.concurrent.SignalExecutors
import org.signal.core.util.inRoundedDays
import org.signal.core.util.logging.Log
import org.signal.core.util.readLength
import org.signal.libsignal.net.RequestResult
import org.signal.libsignal.net.RetryLaterException
import org.signal.libsignal.net.UploadTooLargeException
@@ -50,6 +51,7 @@ import org.whispersystems.signalservice.api.push.exceptions.ResumeLocationInvali
import org.whispersystems.signalservice.internal.crypto.PaddingInputStream
import org.whispersystems.signalservice.internal.push.http.ResumableUploadSpec
import java.io.IOException
import java.net.ProtocolException
import java.util.concurrent.TimeUnit
import kotlin.time.Duration.Companion.days
import kotlin.time.Duration.Companion.milliseconds
@@ -272,6 +274,22 @@ class AttachmentUploadJob private constructor(
resetProgressListeners(databaseAttachment)
throw e
} catch (e: IOException) {
if (e is ProtocolException || e.cause is ProtocolException) {
Log.w(TAG, "[$attachmentId] Length may be incorrect. Recalculating.", e)
val actualLength = SignalDatabase.attachments.getAttachmentStream(attachmentId, 0).use { it.readLength() }
if (actualLength != databaseAttachment.size) {
Log.w(TAG, "[$attachmentId] Length was incorrect! Will update. Previous: ${databaseAttachment.size}, Newly-Calculated: $actualLength")
SignalDatabase.attachments.updateAttachmentLength(attachmentId, actualLength)
uploadSpec = null
} else {
Log.i(TAG, "[$attachmentId] Length was correct. No action needed. Will retry.")
}
}
resetProgressListeners(databaseAttachment)
throw e
}
}
@@ -343,6 +343,7 @@ class UploadAttachmentToArchiveJob private constructor(
ArchiveDatabaseExecutor.runBlocking {
SignalDatabase.attachments.updateAttachmentLength(attachmentId, actualLength)
}
uploadSpec = null
} else {
Log.i(TAG, "[$attachmentId]$mediaIdLog Length was correct. No action needed. Will retry.")
}