[Fix] Don't re-create user on failed remove alias #2049
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
One Line Summary
If a
removeAlais
failed due to a 404 or 410 we incorrectly assumed it was due to the User being deleted, causing it be re-created in a loop.Details
How the bug is triggered
This fixes a bug where the OperationRepo gets stuck in a loop trying to create the user over-and-over again, if OneSignal's backend returned a 404 or 410 when the alias remove was attempted. This can be triggered in these two ways:
addAlias("labelA", "idA"); removeAlias("labelA"); addAlias("labelA", "idA"); removeAlias("labelA")
back-to-back.Internal details
We incorrectly assumed that getting a 404 or a 410 from
DELETE users/by/$aliasLabel/$aliasValue/identity/$aliasLabelToDelete
means the user is gone. It could mean either the User and/or the Alias is gone, either way the end state is the same, the alias no longer exists on that User. If the User was really deleted we will know on the next User operation, and that will handle the create User.Effect on OneSignal's backend
Only apps that used
OneSignal.User.deleteAlias()
, in specific scenarios noted above.deleteAlias
and the rare conditions need to hit this it would have created a storm of POST /users and GET /users calls, along withDELETE users/by/$aliasLabel/$aliasValue/identity/$aliasLabelToDelete
calls.Motivation
Re-creating the user when it isn't needed can create many side-effects we want to avoid.
Scope
Only affects
OneSignal.User.deleteAlias()
Testing
Manual testing
Tested on an Android 14 emulator with the example app calling the following code just after
initWithContext
.Ensured it no longer tries to create a new User over and over in a loop.
Affected code checklist
Checklist
Overview
Testing
Final pass
This change is