You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix bitcoind shutdown hang during initial sync errors and polling
When using bitcoind chain source, `Node::stop()` could hang indefinitely
if called during:
1. Initial sync error backoff (up to 5 minutes of sleep)
2. Active polling operations in the continuous sync loop
This is a more severe variant of the background sync hang issue, as the
bitcoind initial sync loop had NO stop signal checking at all.
The `BitcoindChainSource::continuously_sync_wallets()` initial sync loop
(lines 149-277) performs synchronization on startup. When sync fails
(e.g., "Connection refused" when bitcoind is unavailable), it enters an
exponential backoff retry loop:
- Transient errors: Sleep for `backoff` seconds (10s, 20s, 40s, 80s,
160s, up to 300s)
- Persistent errors: Sleep for MAX_BACKOFF_SECS (300 seconds)
These sleeps had NO stop signal checking. When shutdown was requested:
1. Initial sync fails with connection error
2. Code sleeps for backoff period (up to 5 minutes)
3. User calls `stop()`
4. Stop signal sent but ignored - stuck sleeping
5. Shutdown times out after 5 seconds and aborts
6. Initial sync loop never exits cleanly
The continuous polling loop (lines 296-349) had the same issue as
electrum/esplora - no biased select and no cancellation of in-progress
operations.
1. Added biased `tokio::select!` at loop start to check stop signal
before beginning each sync attempt
2. Wrapped both error backoff sleeps in biased `tokio::select!` to
allow immediate interruption when stop is requested
This ensures that even if bitcoind is down and the node is retrying
with exponential backoff, shutdown completes immediately instead of
waiting up to 5 minutes.
Applied the same biased nested `tokio::select!` pattern used for
electrum/esplora:
- Outer biased select prioritizes stop signal before polling intervals
- Inner nested selects allow cancellation of in-progress operations
Existing unit tests pass. The shutdown will now complete in milliseconds
instead of hanging for minutes when bitcoind is unreachable.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
0 commit comments