Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Don't retry IAM display if 410 is received from backend #2158

Merged
merged 3 commits into from
Aug 5, 2024

Conversation

jennantilla
Copy link
Contributor

@jennantilla jennantilla commented Jul 30, 2024

Description

One Line Summary

Don't retry IAM display if 410 is received from backend

Details

Motivation

In instances where an IAM is disabled mid-session, a 410 is received and is caught in a retrying loop. This change will prevent the retry and just not display the IAM, since it just become disabled.

Scope

Changes to InAppMessagesManager only.

Since this change involves changing the messages list, synchronization was added to makeRedisplayMessagesAvailableWithTriggers and attemptToShowInAppMessage to prevent concurrent modification issues. evaluateInAppMessages was further updated to collect messages for display inside a synchronized block and process them outside to avoid suspension points within critical sections.

Testing

Manual testing

Forced reproduction by setting breakpoint right before IAM is set to display, pausing the IAM from the dashboard, then resuming app flow. A 410 will result.

After updating the code, tested on an Android 14 emulator to see that app resumes normally after IAM is paused in the dashboard. Subsequent 410s are not received and app resumes as expected.

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
    • If it is hard to explain how any codes changes are related to each other then it most likely needs to be more than one PR
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
    • Simplify with less code, followed by splitting up code into well named functions and variables, followed by adding comments to the code.
  • I have reviewed this PR myself, ensuring it meets each checklist item
    • WIP (Work In Progress) is ok, but explain what is still in progress and what you would like feedback on. Start the PR title with "WIP" to indicate this.

This change is Reviewable

@jennantilla jennantilla self-assigned this Jul 30, 2024
@nan-li nan-li self-requested a review July 30, 2024 18:35
@emawby emawby requested a review from jinliu9508 July 30, 2024 18:39
- Changed `messages` from an immutable list to a mutable list
@jennantilla jennantilla force-pushed the fix/iam_410 branch 2 times, most recently from d4b4fce to 1896f10 Compare July 30, 2024 18:46
- Added synchronization to `makeRedisplayMessagesAvailableWithTriggers` and `attemptToShowInAppMessage` to prevent concurrent modification issues
- Refactored `evaluateInAppMessages` to collect messages for display inside a synchronized block and process them outside to avoid suspension points within critical sections
Copy link
Contributor

@jinliu9508 jinliu9508 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, the change works and I am no longer getting repeating 410 errors. Nice work!

@@ -106,6 +106,8 @@ internal class InAppMessagesManager(
private val fetchIAMMutex = Mutex()
private var lastTimeFetchedIAMs: Long? = null

private val lock = Any()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this lock is only for synchronizing 'messages'. In this case we can just call 'synchronized(messages)' instead of introducing a temp lock instance.

- Changed `synchronized(lock)` to `synchronized(messages)`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants