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 subscription/IAM not updated after upgrading from 5.2.0-beta or between 5.1.9 to 5.1.27 #2271

Merged
merged 1 commit into from
Mar 26, 2025

Conversation

jinliu9508
Copy link
Contributor

@jinliu9508 jinliu9508 commented Mar 20, 2025

Description

One Line Summary

Added a MigrationRecovery that detects and recovers a bad state that push sub ID is missing in the config store, caused by a bug in 5.2.0-beta or any version between 5.1.9-5.1.27.

Details

Motivation

5.2.0-beta and all versions between 5.1.9-5.1.27 have a specific logic for push subscription that depends on the result of a remote params fetch. It may cause the push sub ID to be missing from the config model if a postCreateDelay bug also happens that the app is closed within 5 seconds of first start.

Scope

A new MigrationRecovery that will check the status of the config model store and the subscription model store at the start() level.

OPTIONAL - Other

Interface IMigrationRecovery and a base class MigrationRecovery are added for the ease of creating more recovery in the future.

Testing

Unit testing

OPTIONAL - Explain unit tests added, if not clear in the code.

Manual testing

Step to reproduce:

  1. Check out the commit that release 5.2.0-beta that is specifically based on 5.1.25. Beta rebased to 5.1.27 will not have this issue.
  2. close the app within 5 seconds, and reopen it. A 400 error occurs.
  3. Downgrade to 5.1.29. After setting setPaused(false), no IAMs are displayed, and the push subscription is not updated.

Expected Behavior After the Fix:
After downgrade, the push subscription ID is correctly updated. All IAMs are displayed 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
    • PR also includes a new interface IMigrationRecovery and a base class MigrationRecovery for the ease of creating new recovery if needed in the future.
  • 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

@jinliu9508 jinliu9508 requested review from jkasten2 and nan-li March 20, 2025 17:30
@jinliu9508 jinliu9508 force-pushed the migration_recovery branch 3 times, most recently from 53dccfc to 25ff7b2 Compare March 21, 2025 17:19
@jinliu9508 jinliu9508 changed the title Fix subscription/IAM not updated after downgrading from 5.2.0-beta Fix subscription/IAM not updated after upgrading from 5.2.0-beta or between 5.1.9 to 5.1.27 Mar 24, 2025
Copy link
Member

@jkasten2 jkasten2 left a comment

Choose a reason for hiding this comment

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

Some improvements could be made to MigrationRecovery but everything else looks good.


import com.onesignal.debug.internal.logging.Logging

open class MigrationRecovery : IMigrationRecovery {
Copy link
Member

Choose a reason for hiding this comment

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

Let's make this an abstract class, as it isn't indented to be used directly, only extended.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point! This was actually designed but was playing with it as a base class.

Comment on lines 6 to 16
override fun isInBadState(): Boolean {
return false
}

override fun recover() {
// left blank intentionally
}

override fun recoveryMessage(): String {
return ""
}
Copy link
Member

Choose a reason for hiding this comment

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

If this is made an abstract class then these 3 methods do not need to be defined here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have updated the code and tested the change in the latest push.

@jinliu9508 jinliu9508 force-pushed the migration_recovery branch 2 times, most recently from 92344ee to cfa6d8d Compare March 26, 2025 00:55
Comment on lines 6 to 10
abstract override fun isInBadState(): Boolean

abstract override fun recover()

abstract override fun recoveryMessage(): String
Copy link
Member

Choose a reason for hiding this comment

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

These lines don't need to be here at all, these all implied and the complier doesn't require them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I have removed them in the latest push.

@jinliu9508 jinliu9508 merged commit 34eacb2 into main Mar 26, 2025
2 checks passed
@jinliu9508 jinliu9508 deleted the migration_recovery branch March 26, 2025 01:52
@jinliu9508 jinliu9508 mentioned this pull request Mar 26, 2025
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