bug 734624 - java.lang.RuntimeException: An error occured while executing doInBackground() at android.os.AsyncTask.done(AsyncTask.java) caused by: android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed, synchronize inserts to avoid race condition r=lucasr
authorBrad Lassey <blassey@mozilla.com>
Fri, 16 Mar 2012 12:21:06 -0400
changeset 89736 7c6a75b84c1f8d25c460d4e38ee28fc256d40e94
parent 89735 007fd86d0eab0d8ae8173e58f9cfe1e1461909a6
child 89737 837da0646b7dbbf6531c5085ca7416c655bcd455
push id7293
push userblassey@mozilla.com
push dateMon, 19 Mar 2012 17:49:24 +0000
treeherdermozilla-inbound@7c6a75b84c1f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerslucasr
bugs734624
milestone14.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 734624 - java.lang.RuntimeException: An error occured while executing doInBackground() at android.os.AsyncTask.done(AsyncTask.java) caused by: android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed, synchronize inserts to avoid race condition r=lucasr
mobile/android/base/Favicons.java
--- a/mobile/android/base/Favicons.java
+++ b/mobile/android/base/Favicons.java
@@ -251,22 +251,26 @@ public class Favicons {
             if (favicon != null)
                 Log.d(LOGTAG, "Loaded favicon from DB successfully for URL = " + mPageUrl);
 
             return favicon;
         }
 
         // Runs in background thread
         private void saveFaviconToDb(BitmapDrawable favicon) {
-            Log.d(LOGTAG, "Saving favicon on browser database for URL = " + mPageUrl);
-            ContentResolver resolver = mContext.getContentResolver();
-            BrowserDB.updateFaviconForUrl(resolver, mPageUrl, favicon);
+            // since the Async task can run this on any number of threads in the
+            // pool, we need to protect against inserting the same url twice
+            synchronized(mDbHelper) {
+                Log.d(LOGTAG, "Saving favicon on browser database for URL = " + mPageUrl);
+                ContentResolver resolver = mContext.getContentResolver();
+                BrowserDB.updateFaviconForUrl(resolver, mPageUrl, favicon);
 
-            Log.d(LOGTAG, "Saving favicon URL for URL = " + mPageUrl);
-            mDbHelper.setFaviconUrlForPageUrl(mPageUrl, mFaviconUrl);
+                Log.d(LOGTAG, "Saving favicon URL for URL = " + mPageUrl);
+                mDbHelper.setFaviconUrlForPageUrl(mPageUrl, mFaviconUrl);
+            }
         }
 
         // Runs in background thread
         private BitmapDrawable downloadFavicon(URL faviconUrl) {
             Log.d(LOGTAG, "Downloading favicon for URL = " + mPageUrl +
                           " with favicon URL = " + mFaviconUrl);
 
             // due to android bug 6066, we must download the entire image before using it