From 738d5b411bab4e13e176a11f8ae6e6f70337381e Mon Sep 17 00:00:00 2001 From: bitflash-maintainer Date: Wed, 2 Sep 2026 17:10:41 +0000 Subject: worker: let a stop request interrupt the reconnect backoff The retry sleep polled only fShutdown, while the loop around it polls fShutdown, fGenerateBitcoins and nMineMode. That was survivable at a flat 10s. Raising the ceiling to 120s made it expensive: after an operator cleared Generate or switched to Relay mode, the participant session -- and the vfThreadRunning[3] slot that gates restarting it -- stayed held for up to two minutes. Measured with the loop shape replicated and the stop condition flipped 1s into a 120s sleep: 119.01s to notice before, 1.00s after, via either fGenerateBitcoins or nMineMode. The fShutdown path is unchanged at 1.00s. It also narrows the window on a pre-existing unsynchronised read of vfThreadRunning[3] at gui.cpp:901, where a stop-then-start inside it leaves mining silently not restarted. --- src/main.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 69b2c32..b0cdab2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4418,7 +4418,16 @@ bool BitcoinMiner(int nThreadId) } LogPrint("worker", "PoolParticipantMiner: reconnecting in %ds\n", nRetrySecs); - for (int i = 0; i < nRetrySecs && !fShutdown; i++) Sleep(1000); + // Poll everything the enclosing while polls, not just + // fShutdown. Raising the ceiling to 120s made a + // shutdown-only predicate expensive: after the operator + // clears Generate or switches to Relay, the session -- and + // the vfThreadRunning[3] slot that gates restarting it -- + // would stay held for up to two minutes. Measured 119s + // before, 1s after. + for (int i = 0; i < nRetrySecs && !fShutdown && fGenerateBitcoins + && nMineMode == MINE_PARTICIPANT; i++) + Sleep(1000); if (!fHadSession && nRetrySecs < 120) { nRetrySecs *= 2; if (nRetrySecs > 120) -- cgit v1.2.3