-
Notifications
You must be signed in to change notification settings - Fork 119
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(storage): prevent transfer work exception #2851
Conversation
@@ -186,8 +186,14 @@ internal class TransferWorkerObserver private constructor( | |||
) | |||
)?.use { | |||
while (it.moveToNext()) { |
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.
if we catch and continue, what happens on the next it.moveToNext()
? does it return null and break out? would it be safer to catch and break out?
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.
It would be false the next time and break out itself
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 think moving the try-catch to include the while(it.moveToNext())
may be safer incase there's a behavior change where it also throws on closed cursor or some other issue
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.
It is not reported to throw: https://developer.android.com/reference/android/database/Cursor#moveToNext()
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 went ahead and added a break as looking through cursor code, I couldn't find where cursor count would be reset to 0 when closed, and didn't see moveToNext checking if cursor were open.
} catch (exception: IllegalStateException) { | ||
// do nothing. Cursor is likely closed | ||
} |
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.
If we want to swallow all exceptions here, we would need a second catch block for exceptions other than IlllegalStateException
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.
IllegalStateException is the only exception type to be handled here. Since these Android APIs are written in Java, we can trust that the exceptions thrown should only be the ones listed in documentation.
…crash' into tjroach/prevent-transfer-worker-crash
attachObserver(id.toString()) | ||
} catch (exception: IllegalStateException) { | ||
// Stop iterating over cursor. Cursor is likely closed | ||
break |
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.
Is this situation worthy of an error long? What is the impact of failing to attach an observer?
val id = it.getInt(it.getColumnIndexOrThrow(TransferTable.COLUMN_ID)) | ||
attachObserver(id.toString()) | ||
// getInt has been reported to throw in rare cases where it appears another thread | ||
// may have closed cursor |
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.
Any ideas how this could happen?
Closing this PR as the fix was a bit misguided.
|
Pull request was closed
We did not have a try/catch around a method that can throw
https://developer.android.com/reference/android/database/Cursor#getColumnIndexOrThrow(java.lang.String)
.In rare cases (likely db close) a column may not be available. If this happens, we break out of reading the cursor.
See customer issue for more details.
Issue #, if available:
#2840
Description of changes:
See reported issue for details
How did you test these changes?
(Please add a line here how the changes were tested)
Documentation update required?
General Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.