http: Make HTTPRequest::m_client a weak_ptr #36007

pull hodlinator wants to merge 1 commits into bitcoin:master from hodlinator:2026/08/weakptr_client changing 3 files +22 −46
  1. hodlinator commented at 8:03 AM on August 18, 2026: contributor

    Removes the need for HTTPClient::ReleaseRequest() as the client<->request cycle is broken. Not having to remember to call ReleaseRequest() reduces cognitive load.

    Follow-up to #35735.

  2. http: Make HTTPRequest::m_client a weak_ptr
    This removes the need for HTTPClient::ReleaseRequest() as the client<->request cycle is broken. Not having to remember to call ReleaseRequest() reduces cognitive load.
    979a42ec17
  3. DrahtBot added the label RPC/REST/ZMQ on Aug 18, 2026
  4. DrahtBot commented at 8:03 AM on August 18, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

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

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

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

    Type Reviewers
    ACK pinheadmz

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

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

    LLM Linter (✨ experimental)

    Possible typos and grammar issues:

    • // This must happen between, leaving m_send_ready set on an empty buffer. -> sentence is incomplete; missing words make the intended meaning unclear.

    <sup>2026-08-18 08:03:53</sup>

  5. fanquake requested review from pinheadmz on Aug 18, 2026
  6. fanquake requested review from fjahr on Aug 18, 2026
  7. DrahtBot added the label CI failed on Aug 18, 2026
  8. fanquake commented at 9:36 AM on August 18, 2026: member

    Restarted the CI. I think the failure was #34367.

  9. pinheadmz commented at 9:59 AM on August 18, 2026: member

    Will a weak pointer still keep the client connection open if a request is being handled in a worker thread, but the IO loop has dropped I from m_connected ?

  10. DrahtBot removed the label CI failed on Aug 18, 2026
  11. hodlinator commented at 11:36 AM on August 18, 2026: contributor

    Will a weak pointer still keep the client connection open if a request is being handled in a worker thread, but the IO loop has dropped it from m_connected ?

    HTTPRequest::WriteReply() could be holding an ephemeral shared_ptr created by locking the weak_ptr. This would prevent the HTTPRemoteClient from being destroyed directly within HTTPServer::DisconnectClients() running on another thread. Destruction would in that case happen as HTTPRequest::WriteReply() exits, on that thread.

    StopHTTPServer() blocks until the ThreadPool::Stop() has shut down all workers before calling InterruptNet()/JoinSocketsThreads()/ClearConnectedClients().

  12. pinheadmz approved
  13. pinheadmz commented at 11:42 AM on August 18, 2026: member

    untested ACK 979a42ec17369b55a3a20c9e45965e6733fbeb19

    Thanks for the improvement and the explanation 🏆

  14. fanquake merged this on Aug 18, 2026
  15. fanquake closed this on Aug 18, 2026

  16. winterrdog commented at 12:59 PM on August 18, 2026: contributor

    post-merge ACK 979a42ec17369b55a3a20c9e45965e6733fbeb19

  17. fjahr commented at 2:53 PM on August 18, 2026: contributor

    Code change looks good to me, utACK 979a42ec17369b55a3a20c9e45965e6733fbeb19.

    But a bit of documentation is no longer correct after this change. For example inhttpserver.h the DisconnectClients() doc comment still says:

    * Close underlying socket connections for flagged clients
    * by removing their shared pointer from m_connected. If an HTTPRemoteClient
    * is busy in a worker thread, its connection will be closed once that
    * job is done and the HTTPRequest is out of scope.
    

    Now the connection is now closed before the job is done unless I am confused.

    There are also mention of the shared pointers being present in worker threads which does not seem relevant anymore: https://github.com/bitcoin/bitcoin/blob/15a7a4ed7c4d0952ce966087e55a9a3e2f28ec1d/src/httpserver.h#L334 and https://github.com/bitcoin/bitcoin/blob/15a7a4ed7c4d0952ce966087e55a9a3e2f28ec1d/src/httpserver.cpp#L1087.

  18. hodlinator deleted the branch on Aug 18, 2026
  19. hodlinator commented at 9:30 AM on August 19, 2026: contributor

    Thanks for catching the out of date comments @fjahr! Please continue that discussion in follow-up #36020.


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-08-19 11:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me