-
Notifications
You must be signed in to change notification settings - Fork 371
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: bug causes the subscription not updated correctly with a 400 error #2251
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a test too
// Login operation being processed alone will surely be rejected, so we need to add an existing | ||
// external ID to this legacy operation and have it picked up by SetAlias. | ||
if (operations.isEmpty() && _identityModelStore.model.externalId != null) { | ||
loginUserOp.externalId = _identityModelStore.model.externalId |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could there be an issue with properties being set on the wrong user?
Example:
- Login(A)
- setTag(A)
- Login(B)
- setTag(B)
Could this cause User B to get both tag A and B, when it was intended for User A to get tag A and User B to get Tag B?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just tested this scenario and this is how the manual test is setup:
- Fresh install on main branch, right after the anonymous user is created but before the post create delay, programmatically call Login(A), setTag(A), Login(B), setTag(B) altogether and close the app.
- Switch to this branch and update the app.
- Run the app and observe in the dashboard that both users are created successfully and each with the correct tag.
After analyzing the log closely, the code in this if statement will actually never hit for the scenario. OperationRepo will process the operations in this order:
- Create subscription
- Login anonymously
- Refresh user (anonymous)
- Login A AND transfer subscription
- Set Alias for A but got 409
- Refresh user (A)
- Set Tag for A
- Login B AND transfer subscription
- Set Tag for B
Since operations like setting tags does not go with the Login call in one request and the handler for 409 conflict will take care of the IDs, this will not cause the user to be assigned with the wrong tag.
Further more, I tested out that this bug only happen when Login is interrupted with no other operations like set tag or another Login within a few seconds after app starts up.
Integrate postCreateDelay into delayBeforeNextExecution to allow operations to be deleted before the delay
67a0d64
to
3a5447d
Compare
Description
One Line Summary
This PR fixes the issue that causes the subscription to not update correctly or results in a 400 error when calling Login, also handles this bad state when migrating from previous any version.
Details
Motivation
There is an edge case that when the app calls Login with an external ID and forced close within 5 seconds in a fresh install, all future Login calls will be responded with a 400 error and any update to the subscription will fail. This PR aims to prevent this scenario by updating the operation queue correctly and handle the bad state from migration.
Scope
Testing
Manual testing
###Steps to reproduce
This bug can happen strictly when a Login with an externalID is called after the anonymous Login response is received, but the app is force-closed before the 5 seconds PostCreateDelay has reached. One way to reproduce this issue is:
###New Installs
Step 1-3 same as above
4. Re-open the app, wait for the server response and observe that Login with the external ID is successful.
###Updates
Step 1-3 same as above
4. upgrade to this version without uninstalling the previous version or clearing the storage, observe that Login with the externalID is successful.
Affected code checklist
Checklist
Overview
Testing
Final pass
This change is