Bug 615991 - GetNewSessionId can lock the first visit addition if some async write runs before it.
authorMarco Bonardo <mbonardo@mozilla.com>
Thu, 02 Dec 2010 00:14:24 +0100
changeset 59368 e6bea6ba08493aef6b733388c0e37af9d1c060ac
parent 59367 080549b4c0f894b99ebe24bfc9614401a22c36bd
child 59369 9dc0c511381f40eed32a441539cf895daf622d51
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
bugs615991
milestone2.0b8pre
Bug 615991 - GetNewSessionId can lock the first visit addition if some async write runs before it. r=sdwilsh a=blocking
toolkit/components/places/src/nsNavHistory.cpp
--- a/toolkit/components/places/src/nsNavHistory.cpp
+++ b/toolkit/components/places/src/nsNavHistory.cpp
@@ -488,16 +488,22 @@ nsNavHistory::Init()
 
   // Initialize all the items that are not part of the on-disk database, like
   // views, temp tables, functions.  Do not initialize these in InitDBFile, or
   // in case of failure we would mark the database as corrupt and try to
   // replace it, even if it's sane.
   rv = InitAdditionalDBItems();
   NS_ENSURE_SUCCESS(rv, rv);
 
+  // Since some of the APIs are styll synchronous, we need to synchronously get
+  // the sessionId from the database, for visits addition.  The first visit
+  // addition could lock with this synchronous read, thus we query the database
+  // now.  Next calls to GetNewSessionID() will get a incremented cached value.
+  (void)GetNewSessionID();
+
   // Notify we have finished database initialization.
   // Enqueue the notification, so if we init another service that requires
   // nsNavHistoryService we don't recursive try to get it.
   nsRefPtr<PlacesEvent> completeEvent =
     new PlacesEvent(TOPIC_PLACES_INIT_COMPLETE);
   rv = NS_DispatchToMainThread(completeEvent);
   NS_ENSURE_SUCCESS(rv, rv);