From 7daf5e20d9c49179351041b540875db16212d9f4 Mon Sep 17 00:00:00 2001 From: Nicolas Dorier Date: Mon, 22 Jun 2026 10:09:23 +0900 Subject: [PATCH] Improve reliability of wait_and_check_bitcoind Changelog-Fixed: Fixed spurious bitcoind startup failures by retrying bitcoin-cli -rpcwait checks when RPC briefly fails. --- plugins/bcli.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/plugins/bcli.c b/plugins/bcli.c index 67271bb0e9db..4a981a25af68 100644 --- a/plugins/bcli.c +++ b/plugins/bcli.c @@ -780,11 +780,21 @@ static void wait_and_check_bitcoind(struct plugin *p) { struct bcli_result *res; const char **cmd; + int i; /* Special case: -rpcwait flags go on command line, not stdin */ - cmd = gather_args(bitcoind, NULL, "-rpcwait", "-rpcwaittimeout=30", + /* We try 30 times one second rather than one time one second, because + we have seen cases bitcoind becomes available, but rpcwait still just hang + needlessly. */ + cmd = gather_args(bitcoind, NULL, "-rpcwait", "-rpcwaittimeout=1", "getnetworkinfo", NULL); - res = execute_bitcoin_cli(bitcoind, p, cmd, NULL); + for (i = 0; i < 30; i++) { + res = execute_bitcoin_cli(bitcoind, p, cmd, NULL); + if (res->exitstatus != 1) + break; + if (i != 29) + tal_free(res); + } if (res->exitstatus == 1) bitcoind_failure(p,