bitcoindevkit / bitcoindevkit/bdk-dart
ElectrumClient` constructor performs blocking network I/O, causing ANR when called on UI thread
- Dominant language
- Dart
- Stars
- 13
- Forks
- 20
- Avg merge
- 24m
- Merged PRs (30d)
- 3
Description
# `ElectrumClient` constructor performs blocking network I/O, causing ANR when called on UI thread
## Summary
`uniffi_bdkffi_fn_constructor_electrumclient_new` performs a synchronous, blocking TCP `connect()` during construction. When invoked from a platform main/UI thread (e.g. via flutter_rust_bridge / FFI on Android), this blocks the UI thread and produces an Application Not Responding (ANR).
## Environment
- **bdk-ffi** (Dart/Flutter bindings, `libbdk_dart_ffi.so`)
- **Platform:** Android (ARM64)
- **App:** Flutter, BDK called over FFI
## Severity
**High.** On Android, ANRs are tracked in Google Play's Android vitals. Apps that exceed Play's ANR rate threshold receive a "bad behavior" warning in the Play Console and can have their store visibility/discoverability reduced. A constructor that can hang the UI thread on a slow or unreachable Electrum server means any production app shipping bdk-ffi risks elevated ANR rates — making this a release-blocking issue for Flutter wallets in production.
## Stack trace (main thread)
```
main (native):tid=1
#00 pc 0x9bd34 libc.so (__connect + 4)
#01 pc 0x48e4 libnetd_client.so (netdClientConnect + 280)
#02 pc 0xdd6864 libbdk_dart_ffi.so
#03 pc 0x846a84 libbdk_dart_ffi.so
#04 pc 0x82e6b0 libbdk_dart_ffi.so
#05 pc 0x843cfc libbdk_dart_ffi.so
#06 pc 0x843e5c libbdk_dart_ffi.so
#07 pc 0x6d9a38 libbdk_dart_ffi.so
#08 pc 0x535868 libbdk_dart_ffi.so
#09 pc 0x6d9684 libbdk_dart_ffi.so (uniffi_bdkffi_fn_constructor_electrumclient_new + 104)
#10 pc 0x601628 libapp.so <-- Dart caller
```
The main thread is parked inside `__connect` — the network round-trip to the Electrum server runs synchronously on the UI thread.
## Expected behavior
Constructing an `ElectrumClient` should not block the calling thread on network I/O, or the blocking nature should be clearly documented so callers know to construct it off the main thread.
## Actual behavior
The constructor blocks on TCP connect; on a slow or unreachable server this hangs the UI thread long enough to trigger an Android ANR.
Contributor guide
Research direction
Start at the uniffi_bdkffi_fn_constructor_electrumclient_new entry point and trace the ElectrumClient construction path into the synchronous TCP connect. Reproduce the call from a Flutter Android UI thread with a slow or unreachable server. Done means construction no longer causes a UI-thread ANR, or its blocking behavior is clearly documented for callers.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, dart, flutter
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100