Home Ask Login Register

Developers Planet

Your answer is one click away!

cheesus February 2016

onUpgrade race condition in running app

we are using ormlite successfully in our android application; for maintaining database versions, we use an approach like here: http://www.michenux.net/android-database-sqlite-creation-upgrade-245.html

Lately, we've seen "paranormal activity" in the field with apps being in databases states they could not "sanely be", and are trying to find explanations.

One could be that, when a running App is upgraded automatically by Google Play, the onUpgrade() is executed, changing tables and data, while the old (or the new?) App, or maybe their IntentServices concurrently access the database, and get strange results.

(Sadly, there is no easy way to just say "completely stop my app before upgrade, do the upgrade, then completely restart". There is the MY_PACKAGE_REPLACED intent, but opinions on how to use it greatly vary...)

So my question is, is there any safeguard in place that will make onUpgrade() run exclusively, i.e. blocking or locking or synchronizing anything, to make sure another thread does not access my table while I e.g. drop a column (i.e. rename, recreate, copy over data from old tab).

If no, how could I achieve such a thing in the safest way ?

Thanks & kind regards.


cheesus February 2016

Okay, so -

the thorough analysis exposed another (handmade) issue (in our code) that caused all those problems.

So, not to spread any rumours: It seems there is no race condition in onUpgrade() !

It would have been nice to know if it is good practice to have an (exclusive?) transaction block for onUpgrade(), though... I do have one migration using begin transaction, und sqlite throws an error upon nested transactions, so I am pretty sure there is none around onUpgrade() automatically.

For clarification on other issues Yes, Apps are terminated before being upgraded. Only Services might need to re-read config, and alarms (timers) might need restarting.

Post Status

Asked in February 2016
Viewed 3,536 times
Voted 8
Answered 1 times


Leave an answer

Quote of the day: live life