Skip to content

Quit during wallet creation can deadlock qbit-qt #79

Closed

Description

@kiwidream

Acknowledgement

  • I still think this issue should be opened here.

Summary

qbit-qt can enter a mutual wait when application shutdown overlaps successful wallet creation: the GUI thread waits for the wallet-controller worker to exit while that worker synchronously waits for the GUI thread to parent a newly created WalletModel.

A bounded Qt probe reproduced the underlying blocking-connection cycle. A full qbit-qt reproduction proving native/Cmd-Q reachability in the relevant timing window is still pending.

Impact

Quitting while a wallet is being created can leave qbit-qt hung indefinitely and require forced termination during a multi-stage durable operation. After restart, the user may not know whether wallet creation, encryption, descriptor setup, loading, or startup registration completed.

This is a bounded availability and recovery-state defect. No key-confidentiality failure has been demonstrated.

Evidence

  • The affected code is identical on main and 0.1.x as of July 10, 2026.
  • The mutual-wait mechanism is visible in the source.
  • A bounded Qt probe reproduced the blocking-connection behavior.
  • End-to-end native-Quit reachability still needs a latch-controlled qbit-qt test.
  • Code refs:
    • src/qt/walletcontroller.cpp:39-66
    • src/qt/walletcontroller.cpp:117-151
    • src/qt/walletcontroller.cpp:246-279
    • src/qt/guiutil.cpp:384-394
    • src/qt/bitcoin.cpp:329-376
    • src/qt/bitcoin.cpp:459-466
    • src/wallet/wallet.cpp:221-234
    • src/wallet/wallet.cpp:721-729

Failure Path

  1. CreateWalletActivity schedules wallet creation on the wallet-controller worker.
  2. Successful creation synchronously calls NotifyWalletLoaded on that worker.
  3. The controller's load-wallet callback enters getOrCreateWallet, which calls QMetaObject::invokeMethod with GUIUtil::blockingGUIThreadConnection() so setParent runs on the GUI thread.
  4. A native QEvent::Quit can call requestShutdown directly, including while a modal dialog is active.
  5. requestShutdown deletes WalletController on the GUI thread. Its destructor calls quit() and then blocks in wait() while the load-wallet handler is still connected.
  6. quit() does not interrupt the worker's already-running creation callback. The GUI thread waits for the worker, and the worker waits for the GUI thread to service the blocking invoke.

The strongest narrowing condition is timing: application Quit must reach teardown while the worker is in, or is about to enter, the blocking GUI-thread invocation. The source proves the cycle but not how reliably a production native-Quit event hits that window.

Reproduction

  1. Add latches around encrypted wallet creation immediately before NotifyWalletLoaded and immediately before the blocking GUI-thread parent invocation.
  2. Start wallet creation and pause at one latch.
  3. Deliver a native/Cmd-Q QEvent::Quit so the GUI thread enters WalletController teardown.
  4. Release the worker.
  5. Assert that qbit-qt exits within a fixed bound; on affected code, the GUI and worker can remain mutually blocked.
  6. Repeat at database creation, encryption, descriptor setup, NotifyWalletLoaded, and AddWallet boundaries.
  7. After each forced or clean restart, inspect listwalletdir, listwallets, getwalletinfo, active-wallet selection, and startup settings.

Expected Behavior

Shutdown completes within a bounded time without forcing termination. After restart, durable wallet state and GUI/startup registration agree and clearly describe whether creation completed.

Suggested Fix

Define an explicit wallet-controller shutdown phase before joining the worker:

  • stop accepting new load-wallet callbacks and guard model adoption once shutdown begins;
  • remove the worker-to-GUI BlockingQueuedConnection cycle, or drain all model-adoption work while the GUI event loop can still service it;
  • make one thread explicitly own model creation and parenting; and
  • join the activity worker only after no in-flight path can synchronously wait on the GUI thread.

Resetting the load-wallet handler is useful for preventing new callbacks, but the fix must also handle a callback that is already executing.

Verification

Add a latch-controlled Qt regression covering both notification-driven and activity-driven model adoption. Require bounded Quit at every durable creation boundary and an explainable listwalletdir / listwallets / getwalletinfo / startup state after restart. Also rerun ordinary wallet load, unload, create, restore, and GUI shutdown tests.

Activity

  1. added
    bug
    on Jul 10, 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