Skip to content

Commit c928402

Browse files
authored
Retry topic subscription on quota errors using exponential backoff (#6098)
Topic subscription requests might hit a quota, but we can retry these failures with exponential backoff incase they are transient. Retries will only be attempted as long as the app lives and will eventually backoff to 8 hours, so even if an app is consistently at quota, these extra sporadic retries should be harmless. Fixes #6032
1 parent 26c8a5a commit c928402

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

firebase-messaging/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Unreleased
2-
2+
* [changed] Retry Topic Subscribe/Unsubscribe operations with exponential
3+
backoff if they hit a quota error.
34

45
# 24.0.0
56
* [changed] Switched Firelog to use the new TransportBackend.

firebase-messaging/src/main/java/com/google/firebase/messaging/GmsRpc.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ class GmsRpc {
5858
/** Another server error besides ERROR_SERVICE_NOT_AVAILABLE that we retry on. */
5959
static final String ERROR_INTERNAL_SERVER_ERROR = "INTERNAL_SERVER_ERROR";
6060

61+
/**
62+
* A server error that represents hitting topic subscription quota. Trying again here may
63+
* continue to fail, but as long as we use exponential backoff its okay to retry.
64+
*/
65+
static final String TOO_MANY_SUBSCRIBERS = "TOO_MANY_SUBSCRIBERS";
66+
6167
/** Heartbeat tag for firebase iid. */
6268
static final String FIREBASE_IID_HEARTBEAT_TAG = "fire-iid";
6369

firebase-messaging/src/main/java/com/google/firebase/messaging/TopicsSubscriber.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,8 @@ boolean performTopicOperation(TopicOperation topicOperation) throws IOException
251251
} catch (IOException e) {
252252
// Operation failed, retry failed only if errors from backend are server related error
253253
if (GmsRpc.ERROR_SERVICE_NOT_AVAILABLE.equals(e.getMessage())
254-
|| GmsRpc.ERROR_INTERNAL_SERVER_ERROR.equals(e.getMessage())) {
254+
|| GmsRpc.ERROR_INTERNAL_SERVER_ERROR.equals(e.getMessage())
255+
|| GmsRpc.TOO_MANY_SUBSCRIBERS.equals(e.getMessage())) {
255256
Log.e(TAG, "Topic operation failed: " + e.getMessage() + ". Will retry Topic operation.");
256257

257258
return false; // will retry

0 commit comments

Comments
 (0)