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

SQLiteConstraintException on new account #8403

Closed
daniloercoli opened this issue Oct 9, 2018 · 3 comments · Fixed by wordpress-mobile/WordPress-FluxC-Android#1248
Closed

Comments

@daniloercoli
Copy link
Contributor

Created a new wpcom account in the app with success. Navigated the app, and created a new site. Then I sent the app to background.
2 minutes later I re-opened the app and got the following crash. Happened only once, but worth to take a look.

Not quite sure if it's a problem of the app or FluxC. Opening this in this repo for investigation.

10-09 12:12:33.087 19987-19987/org.wordpress.android I/WordPress-STATS: 🔵 Tracked: signed_in
10-09 12:12:33.090 19987-19987/org.wordpress.android D/WordPress-API: Dispatching action: AccountAction-FETCH_ACCOUNT
10-09 12:12:33.104 19987-19987/org.wordpress.android I/WordPress-NOTIFS: notifications update job service > created
10-09 12:12:33.149 19987-19992/org.wordpress.android I/zygote64: Do partial code cache collection, code=503KB, data=321KB
10-09 12:12:33.151 19987-19992/org.wordpress.android I/zygote64: After code cache collection, code=503KB, data=321KB
    Increasing code cache capacity to 2MB
10-09 12:12:33.384 19987-20515/org.wordpress.android I/WordPress-NOTIFS: Sending GCM token to our remote services: dqG2747F0YE:APA91bERnoBKPhrRhmtZhmtaRHB_5g-j-t6peF26pn6Eo6CRM_cyCrHYHHkW0Aj_mIF1AxmuISJ21eyqD58Xf-7a6JMEcqMLmEX1fxoD1eis6OqeNwq5MGRmQzGTjKaSxyU0iz7VbrZF
10-09 12:12:33.447 19987-19987/org.wordpress.android D/WordPress-API: Dispatching action: AccountAction-FETCH_ACCOUNT
10-09 12:12:33.603 19987-19987/org.wordpress.android I/chatty: uid=10120(org.wordpress.android) identical 5 lines
10-09 12:12:33.668 19987-19987/org.wordpress.android I/WordPress-STATS: 🔵 Tracked: signup_epilogue_viewed, Properties: {"source":"email"}
10-09 12:12:34.243 19987-19987/org.wordpress.android I/WordPress-NOTIFS: notifications update service > completed
10-09 12:12:34.244 19987-19987/org.wordpress.android I/WordPress-NOTIFS: notifications update job service > all tasks completed
10-09 12:12:34.312 19987-19987/org.wordpress.android D/WordPress-API: Dispatching action: AccountAction-FETCHED_ACCOUNT
10-09 12:12:34.315 19987-19987/org.wordpress.android I/chatty: uid=10120(org.wordpress.android) identical 1 line
10-09 12:12:34.340 19987-19987/org.wordpress.android D/WordPress-API: Dispatching action: AccountAction-FETCHED_ACCOUNT
10-09 12:12:34.344 19987-19987/org.wordpress.android I/WordPress-READER: User changed, resetting reader db
10-09 12:12:34.352 19987-20150/org.wordpress.android E/SQLiteDatabase: Error inserting ABOUT_ME= SITE_COUNT=0 PRIMARY_SITE_ID=0 PROFILE_URL=http://en.gravatar.com/ufficiofrosinone1 NEW_EMAIL= USER_ID=146022785 USER_NAME=ufficiofrosinone1 [email protected] LAST_NAME= DISPLAY_NAME=ufficiofrosinone1 FIRST_NAME= HAS_UNSEEN_NOTES=true EMAIL_VERIFIED=true DATE= WEB_ADDRESS= PENDING_EMAIL_CHANGE=false TRACKS_OPT_OUT=false _id=1 AVATAR_URL=https://0.gravatar.com/avatar/06a494e343997bc413b07ae06f812d61?s=96&d=identicon VISIBLE_SITE_COUNT=0
    android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: AccountModel._id (code 1555)
        at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)
        at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:783)
        at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788)
        at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86)
        at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1548)
        at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1417)
        at com.yarolegovich.wellsql.InsertQuery.execute(InsertQuery.java:61)
        at org.wordpress.android.fluxc.persistence.AccountSqlUtils.insertOrUpdateAccount(AccountSqlUtils.java:34)
        at org.wordpress.android.fluxc.persistence.AccountSqlUtils.insertOrUpdateDefaultAccount(AccountSqlUtils.java:23)
        at org.wordpress.android.fluxc.store.AccountStore.updateDefaultAccount(AccountStore.java:1145)
        at org.wordpress.android.fluxc.store.AccountStore.handleFetchAccountCompleted(AccountStore.java:943)
        at org.wordpress.android.fluxc.store.AccountStore.onAccountAction(AccountStore.java:841)
        at org.wordpress.android.fluxc.store.AccountStore.onAction(AccountStore.java:768)
        at java.lang.reflect.Method.invoke(Native Method)
        at org.greenrobot.eventbus.EventBus.invokeSubscriber(EventBus.java:485)
        at org.greenrobot.eventbus.EventBus.invokeSubscriber(EventBus.java:479)
        at org.greenrobot.eventbus.AsyncPoster.run(AsyncPoster.java:46)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
        at java.lang.Thread.run(Thread.java:764)
10-09 12:12:34.498 19987-19987/org.wordpress.android I/WordPress-NOTIFS: notifications update job service > destroyed
@daniloercoli daniloercoli added this to the 11.1 milestone Oct 9, 2018
@loremattei loremattei modified the milestones: 11.1 ❄️, 11.2 Nov 5, 2018
@oguzkocer
Copy link
Contributor

This is a FluxC related crash. It looks like just before the crash the account was fetched and tried to be inserted while we already have an account with the same id. This should be where the crash happens: https://github.com/wordpress-mobile/WordPress-FluxC-Android/blob/develop/fluxc/src/main/java/org/wordpress/android/fluxc/persistence/AccountSqlUtils.java#L26-L40

In most cases this should not happen, because it looks like we are checking if there is an account with that ID just before the insert. However, as far as I know this is not guaranteed, because another thread could just add another account in between that time.

I think the easy way, and probably the correct one, to fix this issue is to add an ON CONFLICT REPLACE constraint to AccountModel and avoid the complicated logic we currently have for the insert completely and let Sqlite do its job.

@malinajirka If you end up doing your groundskeeping next week and have bandwidth, do you think you can take a look at this one? I am happy to discuss and test this with you.

@jtreanor jtreanor modified the milestones: 11.2 ❄️, 11.3 Nov 19, 2018
@jtreanor jtreanor modified the milestones: 11.3 ❄️, 11.4 Dec 3, 2018
@jkmassel jkmassel modified the milestones: 11.4 ❄️, 11.5 ❄️ Dec 18, 2018
@daniloercoli daniloercoli modified the milestones: 11.5, 11.6 Dec 21, 2018
@jtreanor jtreanor modified the milestones: 11.6, 11.7 Jan 25, 2019
@loremattei loremattei modified the milestones: 11.7 ❄️, 11.9 Feb 11, 2019
@jtreanor jtreanor modified the milestones: 11.9 ❄️, 12.0 Mar 11, 2019
@jtreanor jtreanor modified the milestones: 12.0 ❄️, 12.1 Mar 25, 2019
@jtreanor jtreanor modified the milestones: 12.1 ❄️, 12.2 Apr 8, 2019
@loremattei loremattei removed this from the 12.2 ❄️ milestone Apr 23, 2019
@aforcier
Copy link
Contributor

aforcier commented Jun 6, 2019

Will be fixed via wordpress-mobile/WordPress-FluxC-Android#1248 once the FluxC hash in WPAndroid has been updated.

@malinajirka
Copy link
Contributor

I've checked Sentry and it seems no-one encountered this crash in the last couple of months. The PR Alex mentioned in the previous comment has been merged and probably fixed the issue -> Closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
9 participants