http: throttle send buffer when client stops draining - #36174
Open
pinheadmz wants to merge 2 commits into
Open
Conversation
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
Contributor
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/36174. ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste LLM Linter (✨ experimental)Possible places where comparison-specific test macros should replace generic comparisons:
2026-09-05 11:50:10 |
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.
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_bufferwithout 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 (reusingMAX_BODY_SIZEhere, open for bikeshedding...) we do not dispatch the request to a worker, leaving it in place asm_req. This is where the tweak to #36123 comes in. In that PR we throttle reads unlessm_reqis present, assuming it is incomplete and needs more data. This commit changes that assumption and so!= State::Completemust be checked in addition.