qt: prevent console hang on large RPC responses#942
Conversation
Running getrawtransaction on a very large non-standard transaction (e.g. the 3.98 MB tx in block 938523) causes the GUI to become completely unresponsive. The hang is in the Qt UI thread: GUIUtil::HtmlEscape() walks the full result string character-by-character, then QTextEdit:: append() re-lays-out an HTML document of the same size, effectively freezing the event loop. Add a 1 MiB guard in RPCExecutor::request() that fires before QString conversion. When the limit is exceeded the user sees the actual byte count and is directed to bitcoin-cli for the full output. Add a mock RPC returning >1 MiB to the Qt unit tests, confirming RPCExecuteCommandLine returns the complete result unmodified (the display guard applies only to the console widget, not the underlying RPC execution path). Fixes bitcoin-core#932
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process. |
|
Hi @hebasto @fanquake , gentle ping on this one! This PR fixes a hard hang in the bitcoin-qt console when running RPC commands that return large payloads (e.g. Root cause: two operations in
Fix: a 1 MiB size guard in Response too large to display (7962624 bytes). Use bitcoin-cli to retrieve the full result. Test coverage: a mock RPC command No behaviour change for normal-sized responses. Happy to adjust the threshold or message wording if needed. Fixes #932. |
Problem
Fixes #932.
Running
getrawtransactionon a very large non-standard transaction in the bitcoin-qt console causes the GUI to become completely unresponsive.Reproduction:
getrawtransaction 30794005e228089a56cca58b6ad85e8cc0667cdc06b0ee6f9fe72aa19f50acd2
The transaction is ~3.98 MB and sits in block 938523. Entering the command above leaves the node window frozen until the process is killed. Reported in #932.
Root cause
The hang is not in the node or the RPC execution path. It occurs in the Qt UI thread after the result is delivered to the console widget.
Two operations in
RPCConsole::message()scale badly with payload size:GUIUtil::HtmlEscape()processes the result string character-by-character. A 3.98 MB transaction encodes to ~7.96 MB of hex, all of which this function walks before returning.QTextEdit::append()is then called with an HTML string of the same magnitude. Qt re-lays-out the entire text document on each call; for a payload this size the layout pass does not complete in any practical amount of time, stalling the event loop indefinitely.Fix
Add a 1 MiB size guard in
RPCExecutor::request(), immediately afterRPCExecuteCommandLine()returns and beforeQString::fromStdString()is called. When the result exceeds the limit the widget receives a short notice instead of the raw output:Response too large to display (7962624 bytes). Use bitcoin-cli to retrieve the full result.
Because the guard fires before
QStringconversion, the oversized string is never converted to UTF-16, never HTML-escaped, and never handed to the text widget.The 1 MiB threshold:
_MiBliteral already present in this file (ui->lineEdit->setMaxLength(16_MiB))Tests
A mock RPC command
rpcLargeOutputis registered insrc/qt/test/rpcnestedtests.cpp. It returns a string of1_MiB + 1bytes. The test asserts thatRPCExecuteCommandLinereturns the complete result unmodified, confirming the size guard inRPCExecutor::request()does not affect the underlying RPC call, only what is rendered in the console widget.