qt: prevent console hang on large RPC responses#942
Open
ShauryaaSharma wants to merge 1 commit into
Open
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
Contributor
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.