Skip to content

Commit

Permalink
Retry topic subscription on quota errors using exponential backoff (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
welishr authored Jul 30, 2024
1 parent 26c8a5a commit c928402
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion firebase-messaging/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Unreleased

* [changed] Retry Topic Subscribe/Unsubscribe operations with exponential
backoff if they hit a quota error.

# 24.0.0
* [changed] Switched Firelog to use the new TransportBackend.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ class GmsRpc {
/** Another server error besides ERROR_SERVICE_NOT_AVAILABLE that we retry on. */
static final String ERROR_INTERNAL_SERVER_ERROR = "INTERNAL_SERVER_ERROR";

/**
* A server error that represents hitting topic subscription quota. Trying again here may
* continue to fail, but as long as we use exponential backoff its okay to retry.
*/
static final String TOO_MANY_SUBSCRIBERS = "TOO_MANY_SUBSCRIBERS";

/** Heartbeat tag for firebase iid. */
static final String FIREBASE_IID_HEARTBEAT_TAG = "fire-iid";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,8 @@ boolean performTopicOperation(TopicOperation topicOperation) throws IOException
} catch (IOException e) {
// Operation failed, retry failed only if errors from backend are server related error
if (GmsRpc.ERROR_SERVICE_NOT_AVAILABLE.equals(e.getMessage())
|| GmsRpc.ERROR_INTERNAL_SERVER_ERROR.equals(e.getMessage())) {
|| GmsRpc.ERROR_INTERNAL_SERVER_ERROR.equals(e.getMessage())
|| GmsRpc.TOO_MANY_SUBSCRIBERS.equals(e.getMessage())) {
Log.e(TAG, "Topic operation failed: " + e.getMessage() + ". Will retry Topic operation.");

return false; // will retry
Expand Down

0 comments on commit c928402

Please sign in to comment.