-
Notifications
You must be signed in to change notification settings - Fork 368
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] loadSavedOperations IndexOutOfBoundsException (5.1.11 only issue) #2081
Conversation
Test proving that loadSavedOperations can throw indexOutOfBoundsException. Real world scenario is this can happen if a few operations are added when the device is offline then the app is restarted.
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.
The testing unit successfully thrown an IndexOutOfBoundException prior to the code change.
The test passed after the second commit.
However, I got a concurrent modification exception from a previous test unit. This is not stably reproducible though. It could be that calling queue.any from two different thread may interrupt each other if they happen to run at the same time.
Since things can be added to the queue before loadSavedOperations is called it has to account for duplicate entries. It did do this, however it was missing the logic to account for not advancing the index on duplicates so an out of bounds was possible. We solved the problem by only incrementing the index if it wasn't a duplicate, however this implementation has a future landmine. If something ever removes something from the queue that loadSavedOperations added and it is still executing index problems can still happen. This scenario never happens now, but a new feature to OperationRepo or a refactor could introduce the problem. A fast follow is recommend so this landmine isn't left here.
feafcda
to
8aa83c5
Compare
Good catch! I have address the |
Tests failed on CI sometimes: Failure 1
Failure 2
These seem to be pre-existing flaky, not related to these changes. (so should be addressed in a different PR) |
Description
One Line Summary
Fixes
IndexOutOfBounds
exception thrown fromOperationRepo.loadSavedOperations
if app was opened offline, some operations done, and then the app is opened again.Details
Motivation
SDK needs to be stable, even if the device goes offline at any point.
Scope
Only affects
OperationRepo.loadSavedOperations
used on cold start of the app.Related
Fixes bug introduced in PR #2068 (released in 5.1.11)
Testing
Unit testing
Manual testing
Tested on an Android 14 emulator.
Affected code checklist
Checklist
Overview
Testing
Final pass
This change is