0

NSS: Retry opening software database

Presumably there's a race condition with session_manager
around creating/opening the software NSS database.
Implement a retry loop as a temporary workaround that should
at least reduce the amount of failures until a proper fix
is implemented.

Bug: 1163303
Test: Manual
Change-Id: Id688d778e55c736b44e97cfdd48187dbf2b856fb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3650747
Auto-Submit: Michael Ershov <miersh@google.com>
Reviewed-by: David Benjamin <davidben@chromium.org>
Commit-Queue: Michael Ershov <miersh@google.com>
Cr-Commit-Position: refs/heads/main@{#1004695}
This commit is contained in:
Michael Ershov
2022-05-18 11:22:12 +00:00
committed by Chromium LUCI CQ
parent 58ef24d369
commit 5ab0c5509b

@ -147,7 +147,21 @@ class NSSInitSingleton {
const std::string modspec =
base::StringPrintf("configDir='sql:%s' tokenDescription='%s'",
path.value().c_str(), description.c_str());
PK11SlotInfo* db_slot_info = SECMOD_OpenUserDB(modspec.c_str());
// TODO(crbug.com/1163303): Presumably there's a race condition with
// session_manager around creating/opening the software NSS database. The
// retry loop is a temporary workaround that should at least reduce the
// amount of failures until a proper fix is implemented.
PK11SlotInfo* db_slot_info = nullptr;
int attempts_counter = 0;
for (; !db_slot_info && (attempts_counter < 10); ++attempts_counter) {
db_slot_info = SECMOD_OpenUserDB(modspec.c_str());
}
if (db_slot_info && (attempts_counter > 1)) {
LOG(ERROR) << "Opening persistent database failed "
<< attempts_counter - 1 << " times before succeeding";
}
if (db_slot_info) {
if (PK11_NeedUserInit(db_slot_info))
PK11_InitPin(db_slot_info, nullptr, nullptr);