commit d0a896ca628bff9eb5710a19bf34849e4ddc0fcf
parent 895bb5f507fbe6f47c313e4d95522cb7dc8c1cfe
Author: t-p-white <towhite@mozilla.com>
Date: Wed, 22 Oct 2025 18:52:38 +0000
Bug 1984713 - Add retry behaviour accessing the Nimbus createMessageHelper fom NimbusMessagingStorage createMessagingHelper which is currently throwing an undocumented exception. r=android-reviewers,gmalekpour
Differential Revision: https://phabricator.services.mozilla.com/D269453
Diffstat:
1 file changed, 25 insertions(+), 4 deletions(-)
diff --git a/mobile/android/android-components/components/service/nimbus/src/main/java/mozilla/components/service/nimbus/messaging/NimbusMessagingStorage.kt b/mobile/android/android-components/components/service/nimbus/src/main/java/mozilla/components/service/nimbus/messaging/NimbusMessagingStorage.kt
@@ -31,6 +31,11 @@ import mozilla.components.service.nimbus.GleanMetrics.Messaging as GleanMessagin
const val MESSAGING_FEATURE_ID = "messaging"
/**
+ * The maximum number of times to retry [NimbusMessagingInterface.createMessageHelper].
+ */
+private const val MAX_RETRY_ATTEMPTS = 5
+
+/**
* Provides messages from [messagingFeature] and combine with the metadata store on [metadataStorage].
*/
class NimbusMessagingStorage(
@@ -55,14 +60,30 @@ class NimbusMessagingStorage(
get() = attributeProvider?.getCustomAttributes(context) ?: JSONObject()
/**
- * Returns a Nimbus message helper, for evaluating JEXL.
+ * Attempts to create and return a Nimbus message helper for evaluating JEXL expressions.
+ *
+ * ⚠️ This method calls [NimbusMessagingInterface.createMessageHelper], which may throw a
+ * [NimbusException]. To improve resilience against transient errors, it retries the operation
+ * up to [MAX_RETRY_ATTEMPTS].
*
* The JEXL context is time-sensitive, so this should be created new for each set of evaluations.
*
- * Since it has a native peer, it should be [destroy]ed after finishing the set of evaluations.
+ * Since it has a native peer, it should be destroyed after finishing the set of evaluations.
*/
- fun createMessagingHelper(): NimbusMessagingHelperInterface =
- nimbus.createMessageHelper(customAttributes)
+ fun createMessagingHelper(): NimbusMessagingHelperInterface {
+ repeat(MAX_RETRY_ATTEMPTS) { attempt ->
+ try {
+ return nimbus.createMessageHelper(customAttributes)
+ } catch (e: NimbusException) {
+ logger.error(
+ "Attempt ${attempt + 1} of $MAX_RETRY_ATTEMPTS to create Nimbus message helper failed",
+ e,
+ )
+ }
+ }
+
+ throw IllegalStateException("The Nimbus createMessagingHelper function threw an exception")
+ }
/**
* Returns the [Message] for the given [key] or returns null if none found.