Skip to content

qbit-qt deadlocks after wallet unlock during deferred P2MR keypool top-up #138

Closed

Description

@kiwidream

Issues, reports or feature requests related to the qbit GUI should be opened here only when they apply to this repository

  • I still think this issue should be opened here

Report

Summary

qbit-qt can deadlock immediately after a correct wallet passphrase is entered. This was observed while creating a transaction with many inputs, but the deadlock occurs during wallet unlock, before transaction preparation or signing starts.

The deadlock involves the GUI thread performing the deferred initial P2MR keypool top-up while the wallet scheduler processes a connected block.

Environment

  • qbit: v1.0.0, arm64 application bundle
  • OS: macOS 26.4
  • CPU: Apple M5 Max
  • Wallet: encrypted descriptor wallet with P2MR keys and a pending deferred create-time keypool top-up

Steps to reproduce

  1. Open an encrypted wallet that has a deferred initial P2MR keypool top-up pending.
  2. In qbit-qt, construct a transaction that requires the wallet to be unlocked. This was observed with a transaction containing many inputs.
  3. Continue until the unlock-wallet dialog appears.
  4. Enter the correct wallet passphrase.

Current behaviour

The passphrase dialog accepts the password, but the GUI then stops responding indefinitely.

During the hang:

  • The process is effectively idle rather than performing CPU-intensive PQC signing.
  • No transaction-preparation or wallet-signing timing messages appear.
  • No walletpqc signing worker threads are running.
  • Node and network activity remain alive.
  • Wallet RPC calls block waiting for the wallet lock.

The final relevant sanitized log line is:

Running deferred create-time keypool top up to 1000 entries per active descriptor

The corresponding completion message is never logged.

Expected behaviour

Wallet unlock should complete without blocking the GUI. Deferred keypool maintenance should not deadlock with block processing, and transaction preparation should proceed after the wallet is unlocked.

Deadlock analysis

Two repeated process samples showed the same stable lock cycle.

GUI thread

The GUI thread follows approximately this path:

AskPassphraseDialog::accept
WalletModel::setWalletLocked
CWallet::Unlock
CWallet::RunPendingInitialKeyPoolTopUp
CWallet::RunPendingInitialKeyPoolTopUpStep
DescriptorScriptPubKeyMan::TopUp
DescriptorScriptPubKeyMan::TopUpWithInternalHintResult
DescriptorScriptPubKeyMan::TopUpWithDBPreparedResult
NotifyCanGetAddressesChanged
ReceiveCoinsDialog canGetAddressesChanged handler
CWallet::CanGetAddresses
std::recursive_mutex::lock

TopUpWithInternalHintResult holds cs_desc_man and an active SQLite write transaction. TopUpWithDBPreparedResult emits NotifyCanGetAddressesChanged() before the outer transaction is committed and before the descriptor lock is released.

Because this happens on the GUI thread, WalletModel uses an automatic/direct Qt invocation. The connected ReceiveCoinsDialog handler immediately calls wallet().canGetAddresses(), which tries to acquire cs_wallet.

Scheduler thread

At the same time, the scheduler thread follows approximately:

CWallet::blockConnected
CWallet::AddToWalletIfInvolvingMe
CWallet::AddToWallet
CWallet::IncOrderPosNext
WalletBatch::WriteOrderPosNext
DatabaseBatch::Write
SQLiteBatch::WriteKey
atomic semaphore wait

blockConnected() holds cs_wallet. Its wallet database write then waits for the SQLite writer currently held by the GUI thread's keypool top-up.

The resulting cycle is:

GUI thread:
  holds descriptor lock / SQLite writer
  waits for cs_wallet

Scheduler thread:
  holds cs_wallet
  waits for SQLite writer

Suggested direction

  1. Do not emit NotifyCanGetAddressesChanged while holding the descriptor mutex or an active wallet database transaction.
  2. Consider making the Qt notification bridge explicitly queued as additional protection against synchronous GUI re-entry.
  3. Avoid performing the complete deferred initial P2MR keypool top-up synchronously from the GUI unlock path. It could instead run through bounded scheduler steps.
  4. Add a regression test that overlaps wallet unlock/deferred top-up with blockConnected() wallet database activity and asserts both operations complete.

Moving only the signing work off the GUI thread does not address this case because the deadlock happens before transaction preparation starts.

Related issues

This appears to be a separate unlock-time path and a concrete descriptor/database/wallet lock cycle.

Activity

  1. added
    bug
    on Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions