RPC console: keep stop and command metadata off the GUI thread #964

Open
opened 2026-10-02 17:29:22 +00:00 by johnny9 · 1 comment
johnny9 commented 2026-10-02 17:29:22 +00:00 (Migrated from github.com)

Parent: #920.

Ordinary RPC commands already run in the background, but the console's literal stop handler enters the RPC dispatcher on the GUI thread. That path can acquire backend locks. Command-completion metadata is also fetched from the backend during GUI setup. These are source-confirmed paths; no long console stall was measured.

Keep shutdown control asynchronous and usable while an ordinary RPC command is blocked. Do not put the operation needed to release a blocked command behind that command. Fetch command metadata outside the GUI thread and publish a cached completion list.

Preserve command parsing, history, selected-wallet routing and help behavior. Show pending work and errors where needed. Ignore late replies after shutdown starts and retain the backend until pending calls finish. Coordinate console retirement with application shutdown under #917.

Test a blocked RPC followed by stop, metadata loading, wallet routing and shutdown with pending replies. Verify continued GUI event processing and safe destruction. Large-output rendering under #828 is a separate concern.

Parent: #920. Ordinary RPC commands already run in the background, but the console's [literal `stop` handler](https://github.com/bitcoin-core/gui-qml/blob/a91f4b4774f25de061fe1a7c132a91ddde117fca/qml/models/rpcconsolemodel.cpp#L341) enters the RPC dispatcher on the GUI thread. That path can acquire backend locks. Command-completion metadata is also fetched from the backend during GUI setup. These are source-confirmed paths; no long console stall was measured. Keep shutdown control asynchronous and usable while an ordinary RPC command is blocked. Do not put the operation needed to release a blocked command behind that command. Fetch command metadata outside the GUI thread and publish a cached completion list. Preserve command parsing, history, selected-wallet routing and help behavior. Show pending work and errors where needed. Ignore late replies after shutdown starts and retain the backend until pending calls finish. Coordinate console retirement with application shutdown under #917. Test a blocked RPC followed by stop, metadata loading, wallet routing and shutdown with pending replies. Verify continued GUI event processing and safe destruction. Large-output rendering under #828 is a separate concern.
jarolrod commented 2026-11-10 22:37:41 +00:00 (Migrated from github.com)

The synchronous stop path also aborts the app when it runs before Core has finished starting.

To reproduce:

  1. Start the app on a profile whose startup is slow enough to act in. I used a regtest wallet that loads at startup, with -keypool=100000, which held "Loading wallet…" for about 35 s.
  2. While it is starting, open Settings → RPC console, or use the Console menu item.
  3. Type stop and press Enter.

The process dies at once with SIGABRT. stderr ends with libc++abi: terminating due to uncaught exception of type UniValue, and debug.log has no Shutdown done. This happened on 3 of 3 offscreen runs and 1 of 1 native run.

Controls during the same startup:

  • getblockcount, help, STOP and stop 1 each add one error row, Loading wallet… (code -28), and the app stays up.
  • Quit exits 0 and logs Shutdown done.
  • stop after startup has finished exits 0.

The literal stop is executed on the calling thread with no try/catch (rpcconsolemodel.cpp#L350-L354). Core's dispatcher throws RPC_IN_WARMUP until initialization completes (server.cpp#L858-L865). The worker used for every other command catches that error and turns it into a row (rpcconsolemodel.cpp#L246-L260). Bitcoin-Qt makes the same unguarded call (rpcconsole.cpp#L1020-L1022), but by source its window is not shown until startup has finished. Here the shell and the console are usable during startup.

#985 at 3d03beb1d931 replaces this call with a shutdown request (rpcconsolemodel.cpp#L369-L372), which removes the throw. I have not run that branch. A test that submits stop before initialization completes would cover this case.

The observed cost was an unclean exit and an OS crash report. Relaunching the same data directory started normally.

Reproduced on merged qt6 at eed1f426fcb6, macOS / Qt 6.9, isolated regtest, offscreen and native. The command was submitted by calling the Enter handler's function through the test bridge, not with a physical Return key. The startup window was lengthened artificially; I did not measure it on a real mainnet node.

The synchronous `stop` path also aborts the app when it runs before Core has finished starting. To reproduce: 1. Start the app on a profile whose startup is slow enough to act in. I used a regtest wallet that loads at startup, with `-keypool=100000`, which held "Loading wallet…" for about 35 s. 2. While it is starting, open **Settings → RPC console**, or use the **Console** menu item. 3. Type `stop` and press Enter. The process dies at once with SIGABRT. stderr ends with `libc++abi: terminating due to uncaught exception of type UniValue`, and `debug.log` has no `Shutdown done`. This happened on 3 of 3 offscreen runs and 1 of 1 native run. Controls during the same startup: - `getblockcount`, `help`, `STOP` and `stop 1` each add one error row, `Loading wallet… (code -28)`, and the app stays up. - Quit exits 0 and logs `Shutdown done`. - `stop` after startup has finished exits 0. The literal `stop` is executed on the calling thread with no `try`/`catch` ([rpcconsolemodel.cpp#L350-L354](https://github.com/bitcoin-core/gui-qml/blob/eed1f426fcb64daa61b004590335a03afe376274/qml/models/rpcconsolemodel.cpp#L350-L354)). Core's dispatcher throws `RPC_IN_WARMUP` until initialization completes ([server.cpp#L858-L865](https://github.com/bitcoin/bitcoin/blob/44901d8f64cb617714707bd025ecd83f108353c2/src/rpc/server.cpp#L858-L865)). The worker used for every other command catches that error and turns it into a row ([rpcconsolemodel.cpp#L246-L260](https://github.com/bitcoin-core/gui-qml/blob/eed1f426fcb64daa61b004590335a03afe376274/qml/models/rpcconsolemodel.cpp#L246-L260)). Bitcoin-Qt makes the same unguarded call ([rpcconsole.cpp#L1020-L1022](https://github.com/bitcoin/bitcoin/blob/44901d8f64cb617714707bd025ecd83f108353c2/src/qt/rpcconsole.cpp#L1020-L1022)), but by source its window is not shown until startup has finished. Here the shell and the console are usable during startup. #985 at `3d03beb1d931` replaces this call with a shutdown request ([rpcconsolemodel.cpp#L369-L372](https://github.com/bitcoin-core/gui-qml/blob/3d03beb1d931548624d3a996ee4e57f703eed3ed/qml/models/rpcconsolemodel.cpp#L369-L372)), which removes the throw. I have not run that branch. A test that submits `stop` before initialization completes would cover this case. The observed cost was an unclean exit and an OS crash report. Relaunching the same data directory started normally. Reproduced on merged `qt6` at `eed1f426fcb6`, macOS / Qt 6.9, isolated regtest, offscreen and native. The command was submitted by calling the Enter handler's function through the test bridge, not with a physical Return key. The startup window was lengthened artificially; I did not measure it on a real mainnet node.
Sign in to join this conversation.
No description provided.