mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 12:20:38 +00:00
http: Log bytes received from client, use to replace receive-throttle regression test #36303
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36303
Loading…
Reference in a new issue
No description provided.
Delete branch "http-log-recv-test-throttle"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #36216
Improves and fixes the test introduced by #36123 to cover regressions in the server's receive throttle. The original test relied on client-side signals to assert server-side behavior which can easily be disrupted by a platform's TCP stack. Macos for example may suddenly re-open a TCP window size based on heuristics out of our control (
SB_AUTOSIZE), despite the application not reading any data from the socket. Macos also may delay transmission of data between 5-60 seconds as the TCP window shrinks (TCPTV_PERSMIN/TCPT_PERSIST/ "silly window syndrome" avoidance). All these behaviors were observed by running the current CI test on my fork hundreds of times, capturing TCP packets and processing them locally against the CI debug log.The improved approach is similar to how we test the send-side throttle in #36174 using debug log messages. This way we test the thing we know we can control (bitcoind).
To introduce the regression patched by #36123 and fail the new test:
For usual bitcoind activity, httpo debug logs will only grow by one extra line per request. Huge requests like those generated by the test may produce a hundred or so lines of "Received data" messages. These are optional debug lines in a worst-case scenario, but reviewers can discuss rate-limiting that log activity if we're afraid it's too much.
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste
<!--meta-tag:bot-skip-->into the comment that the bot should ignore.Conflicts
Reviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.
LLM Linter (✨ experimental)
Possible typos and grammar issues:
macos->macOS[misspelled proper name]2026-09-25 23:37:54
Tested ACK
f86eb92d9atip:
interface_http.pypasseswith the PR unthrottle diff: fails (flood thread assert)
This doesn't seem to be true unless we rename
dl_start_sizetodl_prev_sizeand update the value?hm, must have lost that in a rebase before pushing. thanks for catching, will fix.
Sorry, I think existing code is correct actually:
while True { dl.read() }will always start from where it left off in the previous loop (i.e. only read any new lines added to file since last loop).I didn't have this in the next test though from #36174 though, but could add it here.
Ah yes, I see now that
dl.seek(dl_start_size)is outside the while-loop in this test, unlike the one from #36174.assert_debug_logboth re-opens and re-seeks... toprev_sizewhich is not updated as I was expecting. I guess that serves a paranoid guard against half-completed lines in theassert_debug_logcase.Should this be
time.sleep(0.05)?Currently the test would take 5 minutes to time out
But I guess the way the test is currently set up, because it succeeds after the first time it sees a stall, you have to give the flood some time, maybe instead the number of tries should be greatly reduced?
style nanonit, feel free to disregard and only if retouching:
wrong, see belowYeah it's intentionally a 5 minute timeout (explicit in the comment above) but if you test the regression locally you'll probably find that the test exits much earlier based on the amount of data consumed by the socket:
assert sent_total < len(flood) * 10, f"Client sent too much data: {sent_total}"Both of these boundaries (data sent, time) were chosen at somewhat excessive values to avoid false negatives like the original test.
(speculative; non-blocking)
Both failure limits seem so big, and the test is so eager to pass on the first sign of stalling that this test seems like it could miss actual issues is my hunch, but I don't know what other values to suggest.
crACK
f86eb92d9aIt seems a bit odd to me that the throttle doesn't clamp on once there's a request being processed by the application, but only after that happens and a second message is sent, I think it would be good to also do something like #36276 mainly for code correctness reasons (with a fix for the 50ms select timeout that branch had), but I also recognize that the severity of this DoS vector is extremely low, and this testing approach is much better than the old one which seems inherently flaky for the reasons in PR description, and a good enough fix.
I also think 5 minutes to time out in the failure case is far too generous, intermittent failures are bad but so are tests that are too eager to not fail, and I can't see a good justification for why the http server would continue reading from the socket 60 times after the clamp should have started. IIUC the existing test failure that is observed is because of the ~bug-ish that we'll read one more message after we should have put the clamp on, and I don't see how it could plausibly happen more than once [maybe twice if unlucky] that more data is read, but maybe I have misunderstood something.
The test failure was due to a chain of black-box socket behaviors between the server and client. Without log messages the only way to detect the server throttle was with socket errors on the client side. Problem is there's too many things that can cause those socket errors and even worse, sometimes they go away and data transmission continues. That's all due to behavior in the macos kernel.
I confess I was misled by LLM review that the "bug" was causing the test failures and it was your comment on that PR that really made me step through everything again with my meatball brain and I couldn't answer the fundamental question "how does this patch in the server fix the test?"
I used packet capture to try and nail down the issue and eventually came to the conclusion that there wasn't one issue but many, and all out of control of bitcoind.
And then yeah, its hard to pick constants for how long it should take for something not to happen. If the server code is broken and a ci machine is so slow it takes 6 seconds to read data from a socket then we'll have a false positive. I'd be happy bumping that to 10 or
5 * TIMEOUT_FACTORor something? It just means safe/patched servers will sit in the test for that long before passing.On the other end (5 minutes) I observed some CI runs that false-failed because the TCP was so slow it took a minute for the throttle to kick in at all. Again, could be a role for TIMEOUT_FACTOR.
Could borrow the approach @maflcko wrote in #36324
A little bot told me that since
finditerreturns a single-use iterator,matcheswill already be used up by the time you get tobuffered = ...so it'll stay at 0 no matter what.Observable in the log if you set the flood to never stop (
assert sent_total < len(flood) * 1000000000):TestFramework (DEBUG): Server read 6847787579 bytes, 0 bufferedpush to
b481e99e30Apply timeout_factor to the progress check, like #36324
oops sorry, I only meant to change the pattern:
also should probably drop the unused capture group if you prefer the unnamed capture group approach but that's also not blocking for me:
approach ACK
non-blocking suggestion: do you think
threading.Event()would be a better option since it is an explicit synchronisation primitive
instead of relying on the python's GIL implicitly ?
it could also replace the
time.sleep(0.05)insend_floodwith sth likeflood_open.wait(0.05)which can stop blocking early the instant.set()iscalled elsewhere, so teardown becomes up to 50ms snappier and in the end
not always paying the full sleep in the last loop iteration -- a tiny saving given the
small wait timeout
suggested diff
nit: i think we can rip out the ambiguity like so:
nit: same here. i think we can rip out the ambiguity:
nit: same here. i think we can remove the ambiguity:
reply-to: https://github.com/bitcoin/bitcoin/pull/36303#issuecomment-5821035077
initially, i did think about polling faster at the beginning and only slowing
down once things start to pause, for instance, checking every
250mswhiletotalis still increasing, and only falling back to a longer wait once itstops changing. so, we could catch the stall sooner instead of always waiting out the
entire fixed interval. it would save a few seconds in the fast case like in cases of
local testing
but i think
wait_untilis the better call here: it is the same patterncheck_slow_read_throttle()uses in the upcoming #36324, so this file wouldnot end up with 2 different ways of waiting on the debug log, and CI-speed
differences get handled by one shared setting (
--timeout-factor)nit: Not too important, but I find the nested checks and different exception types, with catching a bit confusing. Also, "Client sent too much data" doesn't sound too helpful to indicate that a block did not occur.
Maybe just a plain:
or (if you insist on hand-written msgs):
(to minimize the diff)
But not important, just a nit.
Also, the comment is wrong, because
send_floodis in a background thread without anexcept?ok, reverting this
👍
Interesting suggestion! I'll try it out
push to 5b4c945d6f933d857f8dcf479bd09c7d583c5fce
include suggestions from @maflcko and @winterrdog, unwrapping
wait_until, usingthreading.Event()and clearing up some log lines.@pinheadmz if leaving as-is can you drop the first match group since it's unused?
or say no and mark this resolved, also fine
yeah sorry, cleaning up...
push to
493850c4c4tACK
493850c4c4successfully built and tested on: FreeBSD
15.0/clang++-19/x86_64reply-to: https://github.com/bitcoin/bitcoin/pull/36303#issue-5518981709
for now, i think we can skip rate-limiting this. normal traffic only produces
one log line per request, and the flood test's worst case (a single ~32MB
request) tops out at around 600-700 lines in well under half a second (tried it
out with this script).
that does not seem too noisy for an opt-in debug category :)
if, indeed, we get empirical evidence that this has become a problem, a simple
fix i can think of right now would be to place the logging behind a tiny
per-client interval, for instance, only emit the debug log if at least 100ms
have passed since the last one for that client
Base:
66776840beb558f7e84451c2c55457f0e06242f0Head:
493850c4c4734acce0f75d1efcffb3868d4235fcDesign and approach
Log per-read counters at trace level (src/httpserver.cpp:971, head)
Receive()reads at most 64 KiB per call, so a 32 MiB request can produce at least 512 unrate-limitedLogDebugentries. That is substantially noisier than the usual one additional line per request for users enabling-debug=http. The functional test framework enables trace logging, so usingLogTracewould preserve its log-based assertion while making these per-read details opt-in at trace level, consistent with the logging guidance for noisy output.🟠 Major
A read plateau does not prove the receive throttle engaged (test/functional/interface_http.py:815, head)
totalis cumulative for the connection, and the checkpoint follows the client's blocking RPC without confirming that the server read it. After observing any positive total, the test passes if no furtherrecv()succeeds for five seconds. That does not establish that flood bytes reached the server or that more bytes were available to read. The PR description reports platform TCP delivery pauses lasting 5–60 seconds, which can satisfy this predicate even if the server would read more data when bytes arrive. Assert server-side evidence that unread bytes remain available, or test the read-interest decision deterministically. No false pass of this replacement test is reported; the concern follows from the predicate and the documented delivery pauses.💡 Suggestion
Resume the flood at the unsent offset (test/functional/interface_http.py:773, head)
If this nonblocking send returns a short positive count,
sent_totaladvances, but the next call sendsfloodagain from byte zero. The stream therefore repeats prefixes instead of completing each request before starting the next, unlike the base test, and may leave malformed request content for post-unblock parsing. The raw bytes still exercise receive throttling, but preserving the constructed pipeline is straightforward: send fromflood[sent_total % len(flood):].Review coverage was incomplete. The archaeology review had incomplete evidence. The alternatives experiment had incomplete evidence. The adversarial_glm review had incomplete evidence.
Full review report
FWIW, https://github.com/hebasto/bitcoin-core-nightly/pull/369.
crtACK
github.com/bitcoin/bitcoin@493850c4c4Code review ACK
493850c4c4Ran interface_http.py ×200 on: macOS 26.6.2 (25G83), arm64 (Apple M2 Pro, Mac14, - Xcode 26.1 (17B55), Apple clang 17.0.0, SDK 26.1
check_pipelined_data_is_throttledpassed every time, couldn't reproduce the intermittent failure. My config differs from the failing nightly runner (run 34438869701 (https://github.com/hebasto/bitcoin-core-nightly/actions/runs/34438869701/job/102749511737)), which was macOS 26.5.2 / Xcode 27, I'm on a newer macOS but an older Xcode, so I can't say whether it's toolchain or OS-specific .A few non-blocking notes: -
The revert diff disables the throttle, so it confirms the test catches unthrottling. IIUC the original intermittent failure was the small one-read window × macOS TCP timing, and a ~64 KB leak would plateau well under the fail threshold.
The OP description is mostly context (the macOS TCP behavior). It'd aid review to also state the change itself: i.e we add a per-read debug log in
HTTPRemoteClient::Receive()and some context on why their etc, and that we rewrites the test to flood the connection and detect the stall from that log.The approach relies on the log being emitted per socket read before request parsing, so the counter tracks bytes drained off the socket even when no request completes. If it moved to request-completion/dispatch, a never-completing flood would emit nothing and the counter couldn't observe an unbounded read. Worth a comment noting this placement is intentional load-bearing.
(It seems in the test prevent that, by the total > 0 check though).
In "test: assert HTTP receive throttle from server-side log"
non-blocking: We could make the verdict entirely bitcoind-based by letting the client be a dumb flooder and, after
wait_until(progress_stalled), asserting the server's received-byte counter stayed reasonable (total < len(flood)*10).ACK
493850c4c4Backported to
32.xin #36427.