Skip to content

Commit 7daf5e2

Browse files
committed
Improve reliability of wait_and_check_bitcoind
Changelog-Fixed: Fixed spurious bitcoind startup failures by retrying bitcoin-cli -rpcwait checks when RPC briefly fails.
1 parent 01074ef commit 7daf5e2

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

plugins/bcli.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,11 +780,21 @@ static void wait_and_check_bitcoind(struct plugin *p)
780780
{
781781
struct bcli_result *res;
782782
const char **cmd;
783+
int i;
783784

784785
/* Special case: -rpcwait flags go on command line, not stdin */
785-
cmd = gather_args(bitcoind, NULL, "-rpcwait", "-rpcwaittimeout=30",
786+
/* We try 30 times one second rather than one time one second, because
787+
we have seen cases bitcoind becomes available, but rpcwait still just hang
788+
needlessly. */
789+
cmd = gather_args(bitcoind, NULL, "-rpcwait", "-rpcwaittimeout=1",
786790
"getnetworkinfo", NULL);
787-
res = execute_bitcoin_cli(bitcoind, p, cmd, NULL);
791+
for (i = 0; i < 30; i++) {
792+
res = execute_bitcoin_cli(bitcoind, p, cmd, NULL);
793+
if (res->exitstatus != 1)
794+
break;
795+
if (i != 29)
796+
tal_free(res);
797+
}
788798

789799
if (res->exitstatus == 1)
790800
bitcoind_failure(p,

0 commit comments

Comments
 (0)