Improve reliability of wait_and_check_bitcoind
What changed, and why it matters
This change is a reliability fix for how Core Lightning waits for the Bitcoin node (bitcoind) to be ready during startup. It replaces one long 30-second wait with 30 shorter 1-second retries to avoid cases where the connection check would hang even though bitcoind was already available. There is no direct security vulnerability being patched; it is a bug-fix for startup failures.
No security action required; treat as a normal reliability improvement. Reviewers may optionally verify that tal_free(res) is NULL-safe and that the loop terminates correctly under all exitstatus values.
Security signals we found
No security-relevant code path modified
No input parsing or authentication logic changed
No memory safety defect evident in diff
Change is purely a retry/timeout reliability improvement
Evidence from the diff
In plugins/bcli.c, wait_and_check_bitcoind() previously invoked bitcoin-cli once with -rpcwait -rpcwaittimeout=30. The patch changes the timeout to 1 second and loops up to 30 times, freeing the previous bcli_result each iteration, breaking early if exitstatus is not 1. This addresses observed spurious startup failures where bitcoind RPC becomes available but -rpcwait hangs. No input validation, privilege, cryptographic, or network-trust boundary changes are present.
Changed components
plugins/bcli.cwait_and_check_bitcoind()Inspect captured patch +13 / −2
diff --git a/plugins/bcli.c b/plugins/bcli.c
index 67271bb0..1b3af2b1 100644
--- a/plugins/bcli.c
+++ b/plugins/bcli.c
@@ -780,11 +780,22 @@ 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 thirty seconds, because
+ * we have seen cases bitcoind becomes available, but rpcwait still just hangs
+ * needlessly.
+ */
+ cmd = gather_args(bitcoind, NULL, "-rpcwait", "-rpcwaittimeout=1",
"getnetworkinfo", NULL);
- res = execute_bitcoin_cli(bitcoind, p, cmd, NULL);
+ res = NULL;
+ for (i = 0; i < 30; i++) {
+ tal_free(res); /* NULL-safe; frees previous attempt */
+ res = execute_bitcoin_cli(bitcoind, p, cmd, NULL);
+ if (res->exitstatus != 1)
+ break;
+ }
if (res->exitstatus == 1)
bitcoind_failure(p,
Why this scored 17/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.