Do not retry auth failures in Svr2MirrorJob.

This commit is contained in:
Greyson Parrelli
2023-07-28 17:25:14 -04:00
parent 2abf30e94b
commit cdce802b32

View File

@@ -13,10 +13,12 @@ import org.thoughtcrime.securesms.jobmanager.impl.NetworkConstraint
import org.thoughtcrime.securesms.keyvalue.SignalStore
import org.thoughtcrime.securesms.pin.SvrRepository
import org.thoughtcrime.securesms.util.FeatureFlags
import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException
import org.whispersystems.signalservice.api.svr.SecureValueRecovery.BackupResponse
import org.whispersystems.signalservice.api.svr.SecureValueRecovery.PinChangeSession
import org.whispersystems.signalservice.api.svr.SecureValueRecoveryV2
import kotlin.concurrent.withLock
import kotlin.time.Duration.Companion.days
/**
* Ensures a user's SVR data is written to SVR2.
@@ -34,7 +36,7 @@ class Svr2MirrorJob private constructor(parameters: Parameters, private var seri
constructor() : this(
Parameters.Builder()
.addConstraint(NetworkConstraint.KEY)
.setLifespan(Parameters.IMMORTAL)
.setLifespan(30.days.inWholeMilliseconds)
.setMaxAttempts(Parameters.UNLIMITED)
.setQueue("Svr2MirrorJob")
.setMaxInstancesForFactory(1)
@@ -86,9 +88,14 @@ class Svr2MirrorJob private constructor(parameters: Parameters, private var seri
Result.success()
}
is BackupResponse.ApplicationError -> {
if (response.exception.isUnauthorized()) {
Log.w(TAG, "Unauthorized! Giving up.", response.exception)
Result.success()
} else {
Log.w(TAG, "Hit an application error. Retrying.", response.exception)
Result.retry(defaultBackoff())
}
}
BackupResponse.EnclaveNotFound -> {
Log.w(TAG, "Could not find the enclave. Giving up.")
Result.success()
@@ -109,6 +116,10 @@ class Svr2MirrorJob private constructor(parameters: Parameters, private var seri
}
}
private fun Throwable.isUnauthorized(): Boolean {
return this is NonSuccessfulResponseCodeException && this.code == 401
}
override fun onFailure() = Unit
class Factory : Job.Factory<Svr2MirrorJob> {