Respect 429 in SVR write requests.

This commit is contained in:
Greyson Parrelli
2026-01-07 12:23:55 -05:00
committed by jeffrey-signal
parent e3b569ca5b
commit 4b41989b30
7 changed files with 39 additions and 10 deletions

View File

@@ -9,6 +9,7 @@ import org.signal.core.models.MasterKey
import org.whispersystems.signalservice.internal.push.AuthCredentials
import java.io.IOException
import kotlin.jvm.Throws
import kotlin.time.Duration
interface SecureValueRecovery {
@@ -88,6 +89,9 @@ interface SecureValueRecovery {
/** There as a network error. Not a bad response, but rather interference or some other inability to make a network request. */
data class NetworkError(val exception: IOException) : BackupResponse()
/** The client request was rate-limited. */
data class RateLimited(val retryAfter: Duration?) : BackupResponse()
/** Something went wrong when making the request that is related to application logic. */
data class ApplicationError(val exception: Throwable) : BackupResponse()
}

View File

@@ -30,6 +30,7 @@ import org.whispersystems.signalservice.internal.push.AuthCredentials
import org.whispersystems.signalservice.internal.util.JsonUtil
import org.whispersystems.signalservice.internal.websocket.WebSocketRequestMessage
import java.io.IOException
import kotlin.time.Duration.Companion.seconds
import org.signal.svr2.proto.BackupResponse as ProtoBackupResponse
import org.signal.svr2.proto.ExposeResponse as ProtoExposeResponse
import org.signal.svr2.proto.RestoreResponse as ProtoRestoreResponse
@@ -220,10 +221,10 @@ class SecureValueRecoveryV2(
}
} catch (e: NonSuccessfulResponseCodeException) {
Log.w(TAG, "[Set] Failed with a non-successful response code exception!", e)
if (e.code == 404) {
BackupResponse.EnclaveNotFound
} else {
BackupResponse.ApplicationError(e)
when (e.code) {
404 -> BackupResponse.EnclaveNotFound
429 -> BackupResponse.RateLimited(e.headers["retry-after"]?.toLongOrNull()?.seconds)
else -> BackupResponse.ApplicationError(e)
}
} catch (e: IOException) {
Log.w(TAG, "[Set] Failed with a network exception!", e)