Skip to content

http: throttle send buffer when client stops draining - #36174

Open
pinheadmz wants to merge 2 commits into
bitcoin:masterfrom
pinheadmz:http-throttle-send
Open

http: throttle send buffer when client stops draining#36174
pinheadmz wants to merge 2 commits into
bitcoin:masterfrom
pinheadmz:http-throttle-send

Conversation

@pinheadmz

Copy link
Copy Markdown
Member

This is a follow-up to #36123 and applies a small tweak to the read-side throttle mechanism in addition to applying a second mechanism to the send-side. If a misbehaving client refuses to read data from the socket, the server will now stop processing requests instead of packing more and more responses to m_send_buffer without bound.

This is a solution to https://github.com/bitcoin-security-council/bitcoin/pull/59 (maybe private, but adding for attestation).

After we parse a complete request from a client, before we dispatch it to a worker, we quickly lock and check the size of m_send_buffer. If there's already 32MiB of data there (reusing MAX_BODY_SIZE here, open for bikeshedding...) we do not dispatch the request to a worker, leaving it in place as m_req. This is where the tweak to #36123 comes in. In that PR we throttle reads unless m_req is present, assuming it is incomplete and needs more data. This commit changes that assumption and so != State::Complete must be checked in addition.

A client streaming pipelined requests into a busy connection
(or any connection whose replies are slower than the sender) could grow
server memory without limit, up to remote OOM.

Stop selecting RecvEvent for clients whose request is being processed;
pipelined data then backs up in the kernel socket buffer, applying TCP
backpressure to the sender. One request per connection is in flight
at a time.

Functional test streams pipelined submitblock requests into a connection
blocked on waitforblockheight. Unpatched builds continue draining the
socket buffer indefinitely, patched builds will stall.
Prevents a memory exhaustion case where a misbehaving client
refuses to read responses and drain the socket buffer. Instead of
packing more data on to the server-side m_send_buffer, stop
dispatching requests from the client to workers
@DrahtBot

DrahtBot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

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

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/36174.

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
Concept ACK winterrdog

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

LLM Linter (✨ experimental)

Possible places where comparison-specific test macros should replace generic comparisons:

  • test/functional/interface_http.pyassert sent <= len(flood) * 10, (...) -> use assert_greater_than_or_equal(len(flood) * 10, sent)
  • test/functional/interface_http.pyassert tries > 0, f"Progress failed to stall ..." -> use assert_greater_than(tries, 0)

2026-09-05 11:50:10

@fanquake fanquake added this to the 32.0 milestone Sep 5, 2026

@winterrdog winterrdog left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants