Skip to content

qt: prevent console hang on large RPC responses#942

Open
ShauryaaSharma wants to merge 1 commit into
bitcoin-core:masterfrom
ShauryaaSharma:fix-qt-console-large-rpc-output
Open

qt: prevent console hang on large RPC responses#942
ShauryaaSharma wants to merge 1 commit into
bitcoin-core:masterfrom
ShauryaaSharma:fix-qt-console-large-rpc-output

Conversation

@ShauryaaSharma

Copy link
Copy Markdown

Problem

Fixes #932.

Running getrawtransaction on 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:

  1. 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.

  2. 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 after RPCExecuteCommandLine() returns and before QString::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 QString conversion, the oversized string is never converted to UTF-16, never HTML-escaped, and never handed to the text widget.

The 1 MiB threshold:

  • reuses the _MiB literal already present in this file (ui->lineEdit->setMaxLength(16_MiB))
  • is well above any realistic interactive debugging output
  • is well below the ~7.96 MiB that triggers the hang

Tests

A mock RPC command rpcLargeOutput is registered in src/qt/test/rpcnestedtests.cpp. It returns a string of 1_MiB + 1 bytes. The test asserts that RPCExecuteCommandLine returns the complete result unmodified, confirming the size guard in
RPCExecutor::request() does not affect the underlying RPC call, only what is rendered in the console widget.

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
@DrahtBot

DrahtBot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.
A summary of reviews will appear here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getrawtransaction hangs node when calling large size tx

2 participants