Bug 870460 - Part 2: Close syncconn for edge cases. r=nwgh
☠☠ backed out by ede558a89106 ☠ ☠
authorJunior Hsu <juhsu@mozilla.com>
Mon, 09 Oct 2017 00:19:00 -0400
changeset 385604 50368fa3e040a806a0b86c0c6471055f4cb41ae1
parent 385603 5aa7980268cb3c335fb7d44090e925563be9d0a2
child 385605 9cbc9faa5c9973e09fa90045f6d4fdcc93eb449e
push id32662
push userryanvm@gmail.com
push dateWed, 11 Oct 2017 21:53:47 +0000
treeherdermozilla-central@3d918ff5d634 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnwgh
bugs870460
milestone58.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 870460 - Part 2: Close syncconn for edge cases. r=nwgh
extensions/cookie/test/unit/test_cookies_async_failure.js
netwerk/cookie/nsCookieService.cpp
--- a/extensions/cookie/test/unit/test_cookies_async_failure.js
+++ b/extensions/cookie/test/unit/test_cookies_async_failure.js
@@ -453,18 +453,19 @@ function* run_test_5(generator)
   do_check_true(do_get_backup_file(profile).exists());
   do_check_eq(do_get_backup_file(profile).fileSize, size);
 
   do_check_eq(Services.cookiemgr.countCookiesFromHost("bar.com"), 0);
   do_check_eq(Services.cookiemgr.countCookiesFromHost("0.com"), 0);
   do_check_eq(do_count_cookies(), 0);
 
   // Close the profile. We do not need to wait for completion, because the
-  // database has already been closed.
-  do_close_profile();
+  // database has already been closed. Ensure the cookie file is unlocked.
+  do_close_profile(sub_generator);
+  yield;
 
   // Clean up.
   do_get_cookie_file(profile).remove(false);
   do_get_backup_file(profile).remove(false);
   do_check_false(do_get_cookie_file(profile).exists());
   do_check_false(do_get_backup_file(profile).exists());
   do_run_generator(generator);
 }
--- a/netwerk/cookie/nsCookieService.cpp
+++ b/netwerk/cookie/nsCookieService.cpp
@@ -50,16 +50,17 @@
 #include "nsNetCID.h"
 #include "nsISimpleEnumerator.h"
 #include "nsIInputStream.h"
 #include "nsAppDirectoryServiceDefs.h"
 #include "nsNetCID.h"
 #include "mozilla/storage.h"
 #include "mozilla/AutoRestore.h"
 #include "mozilla/FileUtils.h"
+#include "mozilla/ScopeExit.h"
 #include "mozilla/Telemetry.h"
 #include "nsIConsoleService.h"
 #include "nsVariant.h"
 
 using namespace mozilla;
 using namespace mozilla::net;
 
 // Create key from baseDomain that will access the default cookie namespace.
@@ -886,16 +887,20 @@ nsCookieService::TryInitDB(bool aRecreat
     // open a connection to the cookie database, and only cache our connection
     // and statements upon success. The connection is opened unshared to eliminate
     // cache contention between the main and background threads.
     rv = mStorageService->OpenUnsharedDatabase(mDefaultDBState->cookieFile,
       getter_AddRefs(mDefaultDBState->syncConn));
     NS_ENSURE_SUCCESS(rv, RESULT_RETRY);
   }
 
+  auto guard = MakeScopeExit([&] {
+    mDefaultDBState->syncConn = nullptr;
+  });
+
   bool tableExists = false;
   mDefaultDBState->syncConn->TableExists(NS_LITERAL_CSTRING("moz_cookies"),
     &tableExists);
   if (!tableExists) {
     rv = CreateTable();
     NS_ENSURE_SUCCESS(rv, RESULT_RETRY);
 
   } else {
@@ -1739,17 +1744,16 @@ nsCookieService::CleanupDefaultDBConnect
   MOZ_ASSERT(!mDefaultDBState->stmtInsert, "stmtInsert has been cleaned up");
   MOZ_ASSERT(!mDefaultDBState->stmtDelete, "stmtDelete has been cleaned up");
   MOZ_ASSERT(!mDefaultDBState->stmtUpdate, "stmtUpdate has been cleaned up");
 
   // Null out the database connections. If 'dbConn' has not been used for any
   // asynchronous operations yet, this will synchronously close it; otherwise,
   // it's expected that the caller has performed an AsyncClose prior.
   mDefaultDBState->dbConn = nullptr;
-  mDefaultDBState->syncConn = nullptr;
 
   // Manually null out our listeners. This is necessary because they hold a
   // strong ref to the DBState itself. They'll stay alive until whatever
   // statements are still executing complete.
   mDefaultDBState->insertListener = nullptr;
   mDefaultDBState->updateListener = nullptr;
   mDefaultDBState->removeListener = nullptr;
   mDefaultDBState->closeListener = nullptr;
@@ -2827,18 +2831,16 @@ nsCookieService::Read()
     Unused << attrs.PopulateFromSuffix(suffix);
 
     nsCookieKey key(baseDomain, attrs);
     CookieDomainTuple* tuple = mReadArray.AppendElement();
     tuple->key = key;
     tuple->cookie = GetCookieFromRow(stmt, attrs);
   }
 
-  mDefaultDBState->syncConn = nullptr;
-
   COOKIE_LOGSTRING(LogLevel::Debug, ("Read(): %zu cookies read", mReadArray.Length()));
 
   return RESULT_OK;
 }
 
 NS_IMETHODIMP
 nsCookieService::ImportCookies(nsIFile *aCookieFile)
 {