Skip to content

Commit 8c241c8

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 e04d2f9 commit 8c241c8

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

plugins/bcli.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -780,11 +780,22 @@ 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 thirty seconds, because
787+
* we have seen cases bitcoind becomes available, but rpcwait still just hangs
788+
* needlessly.
789+
*/
790+
cmd = gather_args(bitcoind, NULL, "-rpcwait", "-rpcwaittimeout=1",
786791
"getnetworkinfo", NULL);
787-
res = execute_bitcoin_cli(bitcoind, p, cmd, NULL);
792+
res = NULL;
793+
for (i = 0; i < 30; i++) {
794+
tal_free(res); /* NULL-safe; frees previous attempt */
795+
res = execute_bitcoin_cli(bitcoind, p, cmd, NULL);
796+
if (res->exitstatus != 1)
797+
break;
798+
}
788799

789800
if (res->exitstatus == 1)
790801
bitcoind_failure(p,

0 commit comments

Comments
 (0)