Skip to content

Review finding: quitting qbit-qt does not cancel an in-flight PSBT signing #308

Closed

Description

@kiwidream

Summary

Application shutdown does not cancel an in-flight PSBT signing worker; shutdown waits for the whole signing, consumes PQC counters, then drops the signed PSBT.

Severity: medium. Found in the 2026-11-04 review of the v1.0.1 change set (all 1.x.x merges since v1.0.0 plus the open PRs that target it), against 1.x.x 21fee6ee8e; area: #145.

Observed

Confidence: confirmed (proven from code).

  • Location: src/qt/walletframe.cpp:60-65 (WalletFrame::prepareForShutdown iterates only mapWalletViews), src/qt/walletview.cpp:116-120 (cancels only the bump and send workers), src/qt/walletframe.cpp:237 (the PSBT dialog is a child of WalletFrame, not of a WalletView), src/qt/psbtoperationsdialog.cpp:93-104 (the only cancel is in the destructor), src/qt/psbtoperationsdialog.cpp:206 (return !dialog.isNull() is always true while the worker runs), src/qt/bitcoin.cpp:353,371-381, src/wallet/load.cpp:183 at 21fee6e.
  • Scenario:
    1. In an encrypted P2MR wallet, open File → Load PSBT with a many-input P2MR PSBT, click Sign, enter the passphrase. The worker starts.
    2. Shutdown is requested by qbit-cli stop, SIGTERM, or OS logoff (the pollShutdownTimer → requestShutdown).
    3. requestShutdown hides all windows. prepareWalletsForShutdown() cancels the send and fee-bump workers only. removeAllWallets() and delete m_wallet_controller then destroy every WalletView and WalletModel.
    4. The PSBT dialog survives, hidden, until delete window in ~BitcoinApplication after exec() returns. So does its worker, and m_sign_cancel_requested is never set. Even during the cancellable preparation phase the worker goes on to reserve counters for every input and sign them all. Sign multi-input P2MR PSBTs outside the qbit-qt GUI thread #140's figure of 149 ms per signature makes 100 inputs about 15 s, before counter writes.
    5. Meanwhile appShutdown() → UnloadWallets → WaitForDeleteWallet blocks until the worker drops its interfaces::Wallet clone.
    6. When the worker finishes, signTransactionFinished takes the !m_wallet_model branch (psbtoperationsdialog.cpp:300). The signed PSBT is discarded and the status "Failed to sign transaction: Wallet is no longer loaded." plus the consumed-usage block is written to a hidden dialog that is never seen. Nothing is logged unless a usage warning fires.
  • Evidence: Traced from code: requestShutdown → BitcoinGUI::prepareWalletsForShutdown → WalletFrame::prepareForShutdown → WalletView::prepareForShutdown. No other code path reaches PSBTOperationsDialog (grep finds a single construction site, and no findChildren). The node side is WalletLoaderImpl::stop → UnloadWallets → WaitForDeleteWallet (interfaces.cpp:713, load.cpp:175-184). Not reproduced.

Impact

  • Shutdown is delayed by the full signing time. That risks an OS-forced kill at logoff.
  • Stateful PQC capacity is consumed after shutdown began, for a result that is thrown away and never shown to the user. cancellation is not propagated. the consumption is invisible.
  • Sign multi-input P2MR PSBTs outside the qbit-qt GUI thread #140's contract asked that "cancellation and shutdown follow explicit stateful-PQC safety rules" and listed an "application shutdown during signing" test. Only dialog destruction and direct model deletion are tested (psbtoperationsdialogtests.cpp:377-414). AppTests covers the send worker only.

Suggested fix

  • Add PSBTOperationsDialog::prepareForShutdown(). It should set m_sign_cancel_requested when !m_sign_counters_reserved and clear the progress dialog. Call it from WalletFrame::prepareForShutdown() for every findChildren<PSBTOperationsDialog*>(), or track PSBT dialogs per wallet model.
  • Replace the dead !dialog.isNull() condition with the cancel flag.
  • Add the AppTests case Sign multi-input P2MR PSBTs outside the qbit-qt GUI thread #140 asked for: quit during PSBT signing before and after counter reservation, asserting a bounded shutdown and no reservation in the first case.
  • Optionally log the consumed usage when a completed result is discarded.

Related: new. It is not covered by the #181 Known limitations or #174, and it is related to but distinct from #286, which covers the background P2MR refill and walletlock.

Activity

  1. added
    bug
    on Nov 4, 2026
  2. kiwidream commented on Nov 6, 2026

    @kiwidream
    MemberAuthor

    Fixed on 1.x.x by #344 (merged as b5486bf). WalletFrame::prepareForShutdown() now reaches every PSBT dialog. Shutdown cancels a signing worker that has not reserved counters yet. A result produced after shutdown began is written to debug.log and, if signed, saved to the data directory as unshown-psbt-<txid>-<time>.psbt. AppTests and new PSBT dialog tests cover both cases and fail without the fix. main gets the fix when 1.x.x is integrated.

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