btcsignals: disconnect callbacks when destroying signal #36930

pull psychemist wants to merge 1 commits into bitcoin:master from psychemist:pr/destroy-signal-disconnect-callbacks changing 2 files +22 −2
  1. psychemist commented at 5:36 PM on November 20, 2026: none

    Follow-up to #36011

    When a connection handle outlives its signal, a callback that was still connected at signal destruction stays alive, and the handle continues to report connected() == true. The referenced PR fix made an explicit disconnect() call release the callback. However, destroying the signal still did not disconnect its callbacks automatically, as pointed out by the author in this #36011 comment.

    This PR's commit disconnects each callback when its signal is destroyed. It extends the callback_destruction test to verify that destroying the signal also releases an idle callback’s captured state and the surviving handle gets disconnected, as suggested in this #36011 comment.

  2. fix: disconnect callbacks when destroying signal
    If a connection handle is still connected when its signal is destroyed,
    it outlives the signal and the handle keeps the callback alive and
    continues to report that it is connected.
    
    Disconnect each callback in the signal destructor. Extend
    callback_destruction test to verify that destroying the signal also
    destroys an idle callback and disconnects the surviving handle.
    1a0f15f45a
  3. DrahtBot commented at 5:36 PM on November 20, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process. A summary of reviews will appear here.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. in src/util/btcsignals.h:227 in 1a0f15f45a
     221 | @@ -222,7 +222,12 @@ class signal
     222 |      using result_type = Combiner::result_type;
     223 |  
     224 |      constexpr signal() noexcept = default;
     225 | -    ~signal() = default;
     226 | +    ~signal()
     227 | +    {
     228 | +        for (const auto& holder : m_connections) {
    


    psychemist commented at 5:59 PM on November 20, 2026:

    I considered removing each holder from the vector before disconnecting it:

            while (!m_connections.empty()) {
                auto holder{std::move(m_connections.back())};
                m_connections.pop_back();
    

    Codex suggested that if one of the callback's captures calls connect() on the same signal from its destructor, it can modify m_connections in-place, invalidating the for loop’s iterator. I haven’t seen an example of this happening in Bitcoin Core so I kept the loop.


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-12-01 02:51 UTC

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