bitcoindevkit / bdk

A modern, lightweight, descriptor-based wallet library written in Rust!
Other
852 stars 307 forks source link

Error syncing wallet via RPC client on macOS system #749

Open notmandatory opened 2 years ago

notmandatory commented 2 years ago

Describe the bug

Unable to sync a regtest wallet with a local bitcoind node via the rpc client on a macOS system using bdk-cli.

To Reproduce

From the bdk-cli repo:

RUST_LOG=debug cargo test --features regtest-bitcoin -- --nocapture

Error is:

thread 'test::test_basic_wallet_op_bitcoind' panicked at 'called `Result::unwrap()` on an `Err` value: CmdExec("[2022-09-10T03:19:40Z ERROR bdk_cli] Rpc(JsonRpc(Transport(SocketError(Os { code: 35, kind: WouldBlock, message: \"Resource temporarily unavailable\" }))))\n")', tests/integration.rs:224:40

Expected behavior

The above test passes on GitHub CI action hosted on Ubuntu 20.04 and should also pass for a macOS system.

Build environment

Additional context

I think this issue is related to https://github.com/apoelstra/rust-jsonrpc/issues/67.

Found this issue while testing https://github.com/bitcoindevkit/bdk-cli/pull/102.

afilini commented 2 years ago

I think the only workaround we have for this is to run the tests with fewer parallel threads, this generally tends to fix the issue.

I think it doesn't happen in the CI because the workers don't have that many cores available, so only a few tests at a time are run in parallel.

notmandatory commented 2 years ago

I tried rerunning cargo test with a single thread, but got the same error.

 RUST_TEST_THREADS=1 cargo test --features regtest-bitcoin

My new theory is that we're running into an issue with bitcoind on macOS where the sqlite DB is very slow using the static linked lib, but runs fine with the MacOS system provided lib (For details see: https://github.com/bitcoin/bitcoin/issues/25724). I re-ran my broken test with a modified version of the utils::new_backend function that uses the env to find my homebrew install of bitcoind and the test is now passing.

BITCOIND_EXE=/opt/homebrew/bin/bitcoind cargo test --features regtest-bitcoin