Repository navigation
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, 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. |
a814772 to
537944c
Compare
537944c to
87dab48
Compare
|
Rebased to latests master |
87dab48 to
99e8803
Compare
|
Rebased and adjusted the function naming. |
hodlinator
left a comment
There was a problem hiding this comment.
Reviewed 99e8803
Nice how you cleaned up the test, makes it easy to grasp.
|
concept ACK, this mitigates slow-loris and perhaps most importantly, mitigates the LLM "findings" reports we keep getting 👍 |
99e8803 to
bfbe9a6
Compare
bfbe9a6 to
c504205
Compare
|
Incorporated the suggested changes by the review from hodlinator. |
c504205 to
2f699f9
Compare
pinheadmz
left a comment
There was a problem hiding this comment.
ACK 2f699f9
Built and tested on macos/arm64. Played with the new timeout using socat to manually make very slow (and then fast) HTTP requests. Mutated the patch a few places to observe test failure, and watched the packets in wireshark throughout to see the trickle.
Reviewed the code and left a few aesthetic nits, no blockers. I found the unit test with the token counter a bit hard to follow but after trying to simplify it myself a few different ways I ended up understanding it and agreeing with the approach.
kimi-k3 gave up trying to write a slow loris attack against this patch ;-)
Show Signature
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
ACK 2f699f91f12e163229edc979769af58457a5f6d0
-----BEGIN PGP SIGNATURE-----
iQJPBAEBCAA5FiEE5hdzzW4BBA4vG9eM5+KYS2KJyToFAmsF95QbFIAAAAAABAAO
bWFudTIsMi41KzEuMTIsMCwzAAoJEOfimEtiick6mF4QANnw9RpPRMezeATOiSHO
q/wt1wVotMJKGJsy5xRwgW+tuegFhKNB73JNT7uC+KNq4KE8InT/Qr4+QqN0mOAN
rQ65V/PzMhVNs7QXT/waw2iPDPMKYY3QooPkvBaviWSrsKuk/DhmbMZw57iJdWqH
IMF1crTEUzcSUmS3S+EawwTyPBTv9vVaYiki1eZBdzAn14mHkKkNALTu33fbvhWd
DcOPrFyrM+9V+OYwHgiKhHv9UOv3tMGpGXGZU2Fs1xBBeq3snslaMhQv7FTzQCs9
YDKdeoehv3/IRRckzoe1OlvtyQ5grkvSFcAHHurDdq2qtV0okhG5zasFkS5K4Aiw
6M4dHtZvmdWn63Vg7NyB/FznGUtl27/yEOiQxmvyOM95dbec5Mbzq3epgoxfvFHZ
jzzwuhR9RIUIlv8Ng2M4kgAcYx6duQpxfzgmbi+py/XWNpk9kIbMi6yNGp2MLupQ
BpriQK890kx4jdY/s0959OeQ5VM0Q31S861duuY4S5rFPHkFsvGKpwg/prZIPsBu
qYcgCrdpLbo6snbD19GxsfLoTcO0BZ2z2BbuAExzWRRdrcZxV+HvrObc32GpGQik
bXVKqsK6JZrHQQmJ45d9pr3OV4HNflsy79qjOseGU+oMvmSh44irHkFO5FKbwBz1
FFtnnO838TnxgW03FAkCFgLr
=IX/c
-----END PGP SIGNATURE-----
pinheadmz's public key is on openpgp.org
21fac44 to
b6dfbd6
Compare
|
Pushed update to fix the lint issue & suggestions of @pinheadmz taken. |
| constexpr std::string_view data{"GET /first HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n" | ||
| "GET /second HTTP/1.1\r\n"}; |
There was a problem hiding this comment.
If you touch again:
| constexpr std::string_view data{"GET /first HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n" | |
| "GET /second HTTP/1.1\r\n"}; | |
| constexpr std::string_view data{"GET /first HTTP/1.1\r\nHost: 127.0.0.1\r\n\r\n" | |
| "GET /second HTTP/1.1\r\n"}; |
hodlinator
left a comment
There was a problem hiding this comment.
ACK b6dfbd6
Nice to avert slow-loris attacks even though RPC is a slightly trusted interface.
I think one could tighten up the functional test a little bit more, but not blocking.
Every read resets the idle timer, so a client that trickles in a request one byte at a time and never finishes it keeps its connection slot for as long as it keeps sending. Add unit and functional tests that pin down this behaviour. The functional test limits the server to one connection and occupies it with such a client. A second client queued behind it gets no response within the timeout. The next commit adds a completion deadline and updates these tests to expect the client to be disconnected.
Every read resets the idle timer, so a client that keeps sending bytes without ever completing a request holds on to its connection slot indefinitely. A handful of them fill -rpcmaxconnections and no other client gets served. Add a second deadline timer that starts at the first byte of a request and is not extended by subsequent reads. It is cleared once the request has been parsed, so a slow RPC keeps its connection. The deadline is restarted while response data goes out. Update the tests from the previous commit: the trickling client is now disconnected once its deadline passes, and the client queued behind it gets a response about one timeout after the first byte. A late response would mean each byte pushed the deadline back, an early one that the slot was freed before the deadline. The debug log check confirms the disconnect was due to the deadline and not the idle timeout.
b6dfbd6 to
1dfe11b
Compare
|
Reviewers, sorry. I have changed the form now to {characterization-test , fix + flipped assertions + new deadline tests). (where new is not new from a reviewer viewpoint but from master / code viewpoint) Pushed new updates that addresses suggestions by @hodlinator and drahtbot |
| waiting_conn.set_timeout(RPCSERVERTIMEOUT + 2) | ||
| with self.node.assert_debug_log(["took too long to send a complete request"]): | ||
| waiting_conn.post_raw('/', '{"method": "getblockcount"}') | ||
| response = waiting_conn.recv_raw() |
There was a problem hiding this comment.
on NetBSD 11.0, check_trickled_request_timeout() fails. waiting_conn.recv_raw() raises TimeoutError because the client-side timeout (RPCSERVERTIMEOUT + 2) expires before a response shows up
on NetBSD, increasing the client-side timeout to any value >= RPCSERVERTIMEOUT * 3 makes the test pass. RPCSERVERTIMEOUT * 2 is still not enough. the test also passes if i remove the client-side timeout altogether. Linux passes without any of these changes, using the original RPCSERVERTIMEOUT + 2
what i cannot tell yet is why it breaks. in the failing run's debug.log, i never see HTTP client took too long to send a complete request
some logs:
test output log
...
2026-11-17T00:23:21.273664Z TestFramework (INFO): Client did not finish sending request before connection was terminated
2026-11-17T00:23:21.279598Z TestFramework (INFO): Check -rpcservertimeout
2026-11-17T00:23:23.747429Z TestFramework (INFO): Check that -rpcservertimeout disconnects clients that never finish a request
2026-11-17T00:23:26.149963Z TestFramework (ERROR): Unexpected exception:
Traceback (most recent call last):
File "/home/user404/bitcoin/test/functional/test_framework/test_framework.py", line 149, in main
self.run_test()
~~~~~~~~~~~~~^^
File "/home/user404/bitcoin/build/test/functional/interface_http.py", line 155, in run_test
self.check_trickled_request_timeout()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/home/user404/bitcoin/build/test/functional/interface_http.py", line 495, in check_trickled_request_timeout
response = waiting_conn.recv_raw()
File "/home/user404/bitcoin/build/test/functional/interface_http.py", line 91, in recv_raw
return self.conn.sock.recv(1024)
~~~~~~~~~~~~~~~~~~~^^^^^^
TimeoutError: timed out
2026-11-17T00:23:26.153951Z TestFramework (INFO): Not stopping nodes as test failed. The dangling processes will be cleaned up later.
2026-11-17T00:23:26.154074Z TestFramework (WARNING): Not cleaning up dir /tmp/bitcoin_func_test_s9etyj6d
2026-11-17T00:23:26.154171Z TestFramework (ERROR): Test failed. Test logging available at /tmp/bitcoin_func_test_s9etyj6d/test_framework.log
...
debug.log excerpt
...
2026-11-17T04:15:04.537793Z [http] [httpserver.cpp:977] [Receive] [http] Received 1 bytes from 127.0.0.1:62906 (id=5): total=240 buffered=1
2026-11-17T04:15:04.786570Z [http] [httpserver.cpp:977] [Receive] [http] Received 1 bytes from 127.0.0.1:62906 (id=5): total=241 buffered=2
2026-11-17T04:15:05.035110Z [http] [httpserver.cpp:977] [Receive] [http] Received 1 bytes from 127.0.0.1:62906 (id=5): total=242 buffered=3
2026-11-17T04:15:05.283603Z [http] [httpserver.cpp:977] [Receive] [http] Received 1 bytes from 127.0.0.1:62906 (id=5): total=243 buffered=4
2026-11-17T04:15:05.532013Z [http] [httpserver.cpp:977] [Receive] [http] Received 1 bytes from 127.0.0.1:62906 (id=5): total=244 buffered=5
2026-11-17T04:15:05.781073Z [http] [httpserver.cpp:977] [Receive] [http] Received 1 bytes from 127.0.0.1:62906 (id=5): total=245 buffered=6
2026-11-17T04:15:06.029565Z [http] [httpserver.cpp:977] [Receive] [http] Received 1 bytes from 127.0.0.1:62906 (id=5): total=246 buffered=7
2026-11-17T04:15:06.278318Z [http] [httpserver.cpp:977] [Receive] [http] Received 1 bytes from 127.0.0.1:62906 (id=5): total=247 buffered=8
2026-11-17T04:15:06.504703Z [http] [httpserver.cpp:957] [Receive] [http] Received EOF from 127.0.0.1:62906 (id=5)
2026-11-17T04:15:06.504776Z [http] [httpserver.cpp:1197] [operator()] [http] Disconnecting HTTP client 127.0.0.1:62906 (id=5)
2026-11-17T04:15:06.504887Z [http] [httpserver.cpp:884] [NewSockAccepted] [http] HTTP Connection accepted from 127.0.0.1:62905 (id=6)
2026-11-17T04:15:06.504943Z [http] [httpserver.cpp:977] [Receive] [http] Received 189 bytes from 127.0.0.1:62905 (id=6): total=189 buffered=189
2026-11-17T04:15:06.505030Z [http] [httpserver.cpp:1174] [TryReadRequestInternal] [http] Received a POST request for / from 127.0.0.1:62905 (id=6)
2026-11-17T04:15:06.505124Z [http] [httpserver.cpp:957] [Receive] [http] Received EOF from 127.0.0.1:62905 (id=6)
2026-11-17T04:15:06.505192Z [http] [httpserver.cpp:1197] [operator()] [http] Disconnecting HTTP client 127.0.0.1:62905 (id=6)
- node's full
debug.loghere -- the tail has the lines of interest

The -rpcservertimeout timer only measures inactivity. Every read from a client resets it, so a client that keeps sending bytes without ever completing a request can hold the connection for ever.
Connection slots are capped by default 16 or by -rpcmaxconnections. Once those slots are taken, the server stops accepting new connections. Because no request ever completes the authentication functions are never hit.
The impact is low because RPC port binds to localhost by default, so this is a robustness fix rather than a remotely exploitable security issue.
How to reproduce
To reproduce: start a node with -rpcmaxconnections=2, open two sockets, and write "GET / HTTP/1.1\r\n" one byte at a time with ten seconds between bytes. bitcoin-cli getblockcount then hangs until one of the (trickling) sockets is closed.
The fix adds a second deadline next to the idle timer. It is armed on the first byte of a request and expires after -rpcservertimeout (the same value as the idle timer). This timer also does not resets or is extended by later reads. Completing request parsing clears the deadline, so a long-running RPC keeps its connection as before. The deadline is deferred while a worker holds the request, for the same reason the idle timer is. It is restarted while response bytes
are written, because the client cannot start a new request during that window. -rpcservertimeout=0 disables both timers. No new option is added.
Disclaimer this bug is found by utilizing ASTRA. Verified using KIMI 3 and Claude.