mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-07-13 17:23:56 +01:00
Respect rate limit in send jobs.
This commit is contained in:
committed by
Michelle Tang
parent
d1c02ac454
commit
635aa8791f
@@ -75,6 +75,7 @@ import org.whispersystems.signalservice.api.messages.shared.SharedContact;
|
||||
import org.whispersystems.signalservice.api.push.ServiceId.ACI;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.NonSuccessfulResponseCodeException;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.ProofRequiredException;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.RateLimitException;
|
||||
import org.whispersystems.signalservice.api.push.exceptions.ServerRejectedException;
|
||||
import org.whispersystems.signalservice.internal.push.BodyRange;
|
||||
|
||||
@@ -173,6 +174,11 @@ public abstract class PushSendJob extends SendJob {
|
||||
if (backoff >= 0) {
|
||||
return TimeUnit.SECONDS.toMillis(backoff);
|
||||
}
|
||||
} else if (exception instanceof RateLimitException) {
|
||||
long backoff = ((RateLimitException) exception).getRetryAfterMilliseconds().orElse(-1L);
|
||||
if (backoff >= 0) {
|
||||
return backoff;
|
||||
}
|
||||
} else if (exception instanceof NonSuccessfulResponseCodeException) {
|
||||
if (((NonSuccessfulResponseCodeException) exception).is5xx()) {
|
||||
return BackoffUtil.exponentialBackoff(pastAttemptCount, RemoteConfig.getServerErrorMaxBackoff());
|
||||
|
||||
+2
-2
@@ -108,7 +108,7 @@ object NetworkResultUtil {
|
||||
404 -> UnregisteredUserException(destination, result.exception)
|
||||
409 -> MismatchedDevicesException(result.parseJsonBody())
|
||||
410 -> StaleDevicesException(result.parseJsonBody())
|
||||
413, 429 -> RateLimitException(result.code, "Rate Limited", Optional.ofNullable(result.header("retry-after")?.toLongOrNull()))
|
||||
413, 429 -> RateLimitException(result.code, "Rate Limited", Optional.ofNullable(result.header("retry-after")?.toLongOrNull()?.seconds?.inWholeMilliseconds))
|
||||
428 -> ProofRequiredException(result.parseJsonBody(), result.header("retry-after")?.toLongOrNull() ?: -1)
|
||||
508 -> ServerRejectedException()
|
||||
else -> result.exception
|
||||
@@ -147,7 +147,7 @@ object NetworkResultUtil {
|
||||
404 -> NotFoundException("At least one unregistered user is message send.")
|
||||
409 -> GroupMismatchedDevicesException(result.parseJsonBody())
|
||||
410 -> GroupStaleDevicesException(result.parseJsonBody())
|
||||
413, 429 -> throw RateLimitException(result.code, "Rate Limited", Optional.ofNullable(result.header("retry-after")?.toLongOrNull()))
|
||||
413, 429 -> throw RateLimitException(result.code, "Rate Limited", Optional.ofNullable(result.header("retry-after")?.toLongOrNull()?.seconds?.inWholeMilliseconds))
|
||||
508 -> ServerRejectedException()
|
||||
else -> result.exception
|
||||
}
|
||||
|
||||
+6
-3
@@ -1944,7 +1944,8 @@ public class SignalServiceMessageSender {
|
||||
MismatchedDevicesException |
|
||||
StaleDevicesException |
|
||||
ProofRequiredException |
|
||||
ServerRejectedException e) {
|
||||
ServerRejectedException |
|
||||
RateLimitException e) {
|
||||
// Non-technical failures shouldn't be retried with socket
|
||||
throw e;
|
||||
} catch (WebSocketUnavailableException e) {
|
||||
@@ -2166,7 +2167,8 @@ public class SignalServiceMessageSender {
|
||||
throwable instanceof MismatchedDevicesException ||
|
||||
throwable instanceof StaleDevicesException ||
|
||||
throwable instanceof ProofRequiredException ||
|
||||
throwable instanceof ServerRejectedException)
|
||||
throwable instanceof ServerRejectedException ||
|
||||
throwable instanceof RateLimitException)
|
||||
{
|
||||
// Non-technical failures shouldn't be retried with socket
|
||||
return Single.error(throwable);
|
||||
@@ -2456,7 +2458,8 @@ public class SignalServiceMessageSender {
|
||||
NotFoundException |
|
||||
GroupMismatchedDevicesException |
|
||||
GroupStaleDevicesException |
|
||||
ServerRejectedException e) {
|
||||
ServerRejectedException |
|
||||
RateLimitException e) {
|
||||
// Non-technical failures shouldn't be retried with socket
|
||||
throw e;
|
||||
} catch (WebSocketUnavailableException e) {
|
||||
|
||||
Reference in New Issue
Block a user