From 2bc4a70eb867c0e53864b54b77ae3eacceef5d33 Mon Sep 17 00:00:00 2001 From: DanS Date: Wed, 28 Oct 2026 12:21:55 -0500 Subject: [PATCH] init: bound the notarizations LOCK wait by wall-clock time The wait for another process to release notarizations/LOCK counted 1 s sleeps, so the time spent probing and a loaded machine stretched the "up to 30 s" to 33-34 s. Wait against a GetTimeMillis() deadline instead, and report the measured elapsed time in the "released after" and "still could not be taken after" lines. Co-Authored-By: Claude Opus 5.5 --- src/init.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 5b4d5cae1..77a496853 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -170,12 +170,12 @@ static NotarizationDB* OpenNotarizationDB(bool fWipe) std::string strError; bool fWaited = false; // the bounded wait for the lock has been used up bool fProbedFree = false; // the probe right before the last open attempt found the lock free - int nWaited = 0; + int64_t nWaitStart = 0; while (true) { try { NotarizationDB* pdb = new NotarizationDB(NOTARIZATION_DB_CACHE_BYTES, false, fWipe); if (fWaited) - LogPrintf("%s: notarizations/LOCK released after %d s; notarizations DB opened\n", __func__, nWaited); + LogPrintf("%s: notarizations/LOCK released after %d s; notarizations DB opened\n", __func__, (GetTimeMillis() - nWaitStart) / 1000); else if (fProbedFree) LogPrintf("%s: notarizations DB opened on retry (notarizations/LOCK was released after the first attempt)\n", __func__); return pdb; @@ -191,9 +191,10 @@ static NotarizationDB* OpenNotarizationDB(bool fWipe) LogPrintf("%s: notarizations DB failed to open (%s): notarizations/LOCK could not be taken (%s); waiting for a previous dragonxd to release notarizations/LOCK (up to %d s)\n", __func__, strError, lockStatus.ToString(), NOTARIZATION_LOCK_WAIT_SECONDS); fWaited = true; - while (nWaited < NOTARIZATION_LOCK_WAIT_SECONDS && !ShutdownRequested()) { - MilliSleep(1000); - nWaited++; + nWaitStart = GetTimeMillis(); + const int64_t nDeadline = nWaitStart + NOTARIZATION_LOCK_WAIT_SECONDS * 1000LL; + while (GetTimeMillis() < nDeadline && !ShutdownRequested()) { + MilliSleep(std::min(1000, std::max(1, nDeadline - GetTimeMillis()))); lockStatus = ProbeLevelDBLock(ndir); if (lockStatus.ok()) break; @@ -201,7 +202,7 @@ static NotarizationDB* OpenNotarizationDB(bool fWipe) } if (!lockStatus.ok()) { LogPrintf("%s: notarizations/LOCK still could not be taken after %d s (%s); using an in-memory notarizations DB for this run (on-disk notarizations DB left untouched)\n", - __func__, nWaited, lockStatus.ToString()); + __func__, (GetTimeMillis() - nWaitStart) / 1000, lockStatus.ToString()); return new NotarizationDB(NOTARIZATION_DB_CACHE_BYTES, true, false); } }