Skip to content

lightning-block-sync::HttpClient::send_request_with_retry panics if bitcoind crashes #930

@sr-gi

Description

@sr-gi

If a query to bitcoind's RPC interface is performed once bitcoind is off / has crashed (but it was previously reachable), send_request_with_retry does eventually panic with:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 22, kind: InvalidInput, message: "Invalid argument" }'

The issue comes from unwrapping https://github.com/rust-bitcoin/rust-lightning/blob/main/lightning-block-sync/src/http.rs#L165.

Here's a minimal example to reproduce (using BitcoindClient from https://github.com/lightningdevkit/ldk-sample/blob/main/src/bitcoind_client.rs):

use crate::bitcoind_client::BitcoindClient;
use std::sync::Arc;
use std::{thread, time};

#[tokio::main]
pub async fn main() {
    let host = String::from("localhost");
    let port = 18443;
    let user = String::from("user");
    let password = String::from("passwd");

    // Initialize our bitcoind client.
    let bitcoin_cli = match BitcoindClient::new(host, port, user, password).await {
        Ok(client) => Arc::new(client),
        Err(e) => {
            println!("Failed to connect to bitcoind client: {}", e);
            return;
        }
    };

    let polling_delta = time::Duration::from_secs(1);

    loop {
        match bitcoin_cli.get_best_block_hash().await {
            Ok(_) => (),
            Err(_) => println!("Connection lost with bitcoind"),
        };

        thread::sleep(polling_delta);
    }
}

Steps to reproduce:

  • cargo run with bitcoind running
  • stop bitcoind

Result:

Connection lost with bitcoind
Connection lost with bitcoind
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 22, kind: InvalidInput, message: "Invalid argument" }', /Users/sergi/.cargo/git/checkouts/rust-lightning-6850882c83c110d8/499d84c/lightning-block-sync/src/http.rs:164:48
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions