mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:47:36 +00:00
http: Improve HTTPRemoteClient::MaybeDisconnect() #36159
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!36159
Loading…
Reference in a new issue
No description provided.
Delete branch "2026/09/should_disconnect"
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?
Issues
#35182 had 1 case where we flag a client for disconnect where we do not log the reason.
#35829 introduced the somewhat poorly named non-
constHTTPRemoteClient::MaybeDisconnect(). It also lacks testing.The control-flow in
MaybeDisconnect()/ShouldDisconnect()is somewhat complex. https://github.com/bitcoin/bitcoin/pull/35829#discussion_r3846342291Commits solving these issues in same order
HTTPRemoteClient::m_disconnect = trueMaybeDisconnect()toShouldDisconnect()and make itconstShouldDisconnect()ShouldDisconnect()ShouldDisconnect()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:
src/test/httpserver_tests.cpp:claiming its able to send everything→claiming it's able to send everything[typo:itsshould beit's]2026-10-06 19:40:23
Concept ACK
Built the four commits and mutation-tested the changed branches.
nowis a whole second, taken before the clients exist and compared against anm_idle_sincethey stamp later, so the checks expecting a disconnect atnow + timeout + 1sonly hold while both fall in the same second. About 0.6ms sits in between onbusy_slow, and a rollover there makes the comparison30s > 30s. Forced one to confirm. Worth takingnowper block, afterWriteReply()forbusy_slow?This also stops the idle line being logged when the client is already flagged. Before,
is_idlewas worked out first and logged insideif (m_disconnect || is_idle), so a client already flagged and past the timeout got both lines. Looks like an improvement, since that line was claiming a timeout for a client leaving for another reason. Worth a mention in the commit message, since it saysrefactor:?A connection that is accepted and never sends anything keeps
m_connection_busyat its initialtrue, so thedisconnect_allbranch never picks it up. InsideShouldDisconnect()only the idle timeout is left, and with-rpcservertimeout=0there is no idle timeout either. On regtest shutdown goes from 0.7s to 30.7s and ends in aForce-disconnectingwarning. At the default of 30s that timeout andStopHTTPServer()'s own deadline are the same number. Releasing them at once would give up the503a client can still get today by sending afterstop. Is the wait deliberate?ZeroSock::Send()already returnslen, so could this just be aZeroSock?Every client here is
HTTP/1.0, som_keep_aliveis never true and the branch for a healthy persistent connection is only ever asserted not firing. Replacing that condition withfalseleaves this test green. Worth one more client?Thanks for the feedback @jeanpablojp (https://github.com/bitcoin/bitcoin/pull/36159#pullrequestreview-5114081037)!
Addressed all of it to some extent in the latest push (
352fdc2797) + inline comment. Opted for mocking the clock and freeze it rather than trying to keep up with the current time of the actual clock as it drifts throughout the added test case.re https://github.com/bitcoin/bitcoin/pull/36159#discussion_r3934900182:
You are pointing out behavior on master, right?
Maybe we could disconnect clients quicker if they just open the connection and don't send anything, within 5 seconds or so? Not sure I want to increase the complexity of this PR though. That would probably introduce another timeout-setting.
🚧 At least one of the CI tasks failed.
Task
MSan: https://github.com/bitcoin/bitcoin/actions/runs/33990407720/job/101371509013LLM reason (✨ experimental): CI failed during the build link step (
bitcoin-wallet) due to ald.bfderror: “bad reloc symbol index … in section.debug_addr,” causing the final link to fail.Hints
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
An intermittent issue.
Leave a comment here, if you need help tracking down a confusing failure.
Yes, master, but also measured at the merge-base and on today's master, the same both times, under a second to shut down with no such connection open and 30.7s with one at
-rpcservertimeout=0.The slots are the sharper half. With
-rpcmaxconnections=4and four sockets that connect and send nothing, a normal call has to wait for the idle timeout to free one, and-rpcservertimeout=0means nothing frees them. Agreed it does not belong here though, and your five seconds sounds like the right direction. Happy to open a follow-up.tACK
352fdc2797successfully built and tested on this toolchain: Debian/
clang++ 18/x86_64.P.S: the CI failure is completely independent of the changes introduced by this PR
ACK
352fdc2797Built and tested on macos/arm64. Reviewed the changes and checked with both meatball brain and LLM that the refactor didn't change behavior. Great new text coverage helps with that a lot as well. Left a few non blocking suggestions.
Show Signature
pinheadmz's public key is on openpgp.org
Possible impovement: move the Log("Disconnecting client...") here inside the lambda. Then
ShouldDisconnect()could be clarified by filling those blank spaces withreturnstatements352fdc2797tiny nit, comment placement: I think this comment can just be removed or something added to the above comment that this is where even keep-alive clients get dropped, because we are shutting down.
your other comments all describe a logic decision about to be made on the next line and so I think its a bit confusing to have this written here.
Base:
aef8a04966d7ab6c04edc5d19b733e78205405deHead:
2abf671d2e14b5ceb91fb570258945b41ef78299💡 Suggestion
Check shutdown while response bytes remain buffered (src/test/httpserver_tests.cpp:834, head)
Before draining the buffer, also assert
!busy_slow->ShouldDisconnect(now + timeout - 1s, timeout, /*disconnect_all=*/true).WriteReply()clearsm_req_busy, but thisSlowSocketstill has buffered response bytes andm_connection_busyremains true. The existing shutdown check at line 828 runs only while the worker is handling the request, so without this assertion a regression that checksm_req_busyinstead ofm_connection_busycould disconnect before the response is fully sent and still pass these tests.Review coverage was incomplete. The archaeology review had incomplete evidence.
Full review report
@hodlinator do you want to take @pinheadmz's nits? Asking because this is already a followup/refactoring pull request.
re https://github.com/bitcoin/bitcoin/pull/36159#issuecomment-6012097013 & https://github.com/bitcoin/bitcoin/pull/36159#pullrequestreview-5306713554:
Thanks for the review @pinheadmz, applied your neat nits. Also attempted to improve some comments.
git range-diff 352fdc27~4...352fdc27 2abf671d~4...2abf671dACK
2abf671d2eBuilt, tested. Re-reviewed. Thanks for taking my suggestions!
Show Signature
pinheadmz's public key is on openpgp.org
reACK
2abf671d2ecosmetic nit: now that every branch
returns, i think plainifs (withoutelse) would read a bit nicer here. right now, the comments sit between areturn true;and the next} else if, so they look like they belong to the previous block (kind of puzzled me at first glance but later on i realised what you meant). with separateifs each comment lands right above the condition it explains, and the behavior would be identical. sth like:non-blocking, it is :)
That's fair, the comments before the prior scope's ending curly brace didn't sit 100% comfortably with me either. Will do if I need to rebase again or touch for other reasons.
ACK
2abf671d2e