shutdown: Destroy kernel last, make test shutdown order consistent #28224

pull TheCharlatan wants to merge 2 commits into bitcoin:master from TheCharlatan:testSetupDestructorOrder changing 2 files +4 −2
  1. TheCharlatan commented at 8:29 PM on August 5, 2023: contributor

    The destruction/resetting of node context members in the tests should roughly follow the behavior of the Shutdown function in init.cpp.

    This was originally requested by MarcoFalke in this comment in response to the original pull request introducing the kernel::Context.

  2. DrahtBot commented at 8:29 PM on August 5, 2023: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK ryanofsky, maflcko, achow101

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

  3. DrahtBot added the label Tests on Aug 5, 2023
  4. DrahtBot added the label CI failed on Sep 4, 2023
  5. DrahtBot removed the label CI failed on Sep 5, 2023
  6. achow101 requested review from theuni on Sep 20, 2023
  7. achow101 requested review from ryanofsky on Sep 20, 2023
  8. in src/test/util/setup_common.cpp:147 in 960112dbb1 outdated
     143 | @@ -144,6 +144,7 @@ BasicTestingSetup::BasicTestingSetup(const ChainType chainType, const std::vecto
     144 |  
     145 |  BasicTestingSetup::~BasicTestingSetup()
     146 |  {
     147 | +    m_node.kernel.reset();
    


    ryanofsky commented at 4:21 PM on September 29, 2023:

    In commit "tests: Reset node context members on ~ChainTestingSetup" (960112dbb1fb028b73b6e83932dd457f5a69ab5d)

    I think this change makes sense but the log message is misleading because in the Shutdown() function the kernel context is currently destroyed before chainman, mempool, scheduler, not after:

    https://github.com/bitcoin/bitcoin/blob/d18a8f6f6969487021b8fd50391a2a8d1dc29844/src/init.cpp#L346-L350

    The test code is more correct than the Shutdown() code because ~BasicTestingSetup runs after ~ChainTestingSetup, and the chainman and scheduler objects should be destroyed before kernel context because they might rely on it.

    It'd be good to either clarify the log message in this commit to say mention this part of the change doesn't match Shutdown function, or update the Shutdown function to destroy the kernel context last like the test. (I could also update the Shutdown function in #28051 if you want this PR to be test-only)

  9. ryanofsky approved
  10. ryanofsky commented at 4:36 PM on September 29, 2023: contributor

    Code review ACK 960112dbb1fb028b73b6e83932dd457f5a69ab5d

  11. maflcko commented at 9:24 AM on October 20, 2023: member

    Are you still working on this?

  12. TheCharlatan commented at 9:32 AM on October 20, 2023: contributor

    Yes.

  13. maflcko commented at 9:34 AM on October 20, 2023: member

    I think there is an outstanding comment: #28224 (review) ?

  14. TheCharlatan force-pushed on Oct 21, 2023
  15. TheCharlatan commented at 11:00 AM on October 21, 2023: contributor

    Updated 960112dbb1fb028b73b6e83932dd457f5a69ab5d -> 99a668ceb80b8241c9eb24dca2858dbdd3ddf7ee (testSetupDestructorOrder_0 -> testSetupDestructorOrder_1, compare)

    • Addressed @ryanofsky's comment, ammending commit to adjust the reset order in the Shutdown function.
  16. DrahtBot added the label CI failed on Oct 21, 2023
  17. ryanofsky approved
  18. ryanofsky commented at 2:23 PM on October 23, 2023: contributor

    Code review ACK 99a668ceb80b8241c9eb24dca2858dbdd3ddf7ee

    Changes look good, but I would suggest changing the PR title to something like: "shutdown: destroy kernel last and make test shutdown order consistent" because the current title "tests: Reset node context members on ~ChainTestingSetup" makes it seems like this is a test-only change.

    Also think it would be better to split changes in init.cpp and setup_common.cpp into separate commits. The changes are both related to shutdown but they have different rationales and effects, so it doesn't really make sense for them to be in the same commit.

  19. TheCharlatan renamed this:
    tests: Reset node context members on ~ChainTestingSetup
    shutdown: Destroy kernel last, make test shutdown order consistent
    on Oct 24, 2023
  20. shutdown: Destroy kernel last
    Currently the shutdown function resets the kernel before the
    chainman and scheduler. Invert this order by resetting the kernel
    last, since they might rely on the kernel.
    9759af17ff
  21. tests: Reset node context members on ~BasicTestingSetup
    The destruction/resetting of node context members in the tests should
    roughly follow the behaviour of the Shutdown function in `init.cpp`.
    c1144f0076
  22. TheCharlatan force-pushed on Oct 24, 2023
  23. TheCharlatan commented at 6:43 AM on October 24, 2023: contributor

    Updated 99a668ceb80b8241c9eb24dca2858dbdd3ddf7ee -> c1144f0076339c775f41d4b5fcfdc72191440d96 (testSetupDestructorOrder_1 -> testSetupDestructorOrder_2, compare)

  24. maflcko removed the label Tests on Oct 24, 2023
  25. ryanofsky approved
  26. ryanofsky commented at 6:47 PM on October 24, 2023: contributor

    Code review ACK c1144f0076339c775f41d4b5fcfdc72191440d96. No code changes since last review, just updated commits and descriptions

  27. maflcko commented at 7:07 AM on October 25, 2023: member

    ACK c1144f0076339c775f41d4b5fcfdc72191440d96 🗣

    <details><summary>Show signature</summary>

    Signature:

    untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
    RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
    trusted comment: ACK c1144f0076339c775f41d4b5fcfdc72191440d96 🗣
    T9dJ5U2qRZJzAofSxNNeOCDY1x9g1v2UzSnLfzGQ+Ge86LGQmtA47PGOhyV4baDkH4joyvRrBHb2K0taFvI/Dw==
    

    </details>

  28. maflcko assigned ryanofsky on Oct 25, 2023
  29. DrahtBot removed the label CI failed on Oct 25, 2023
  30. achow101 commented at 9:07 PM on November 7, 2023: member

    ACK c1144f0076339c775f41d4b5fcfdc72191440d96

  31. achow101 merged this on Nov 7, 2023
  32. achow101 closed this on Nov 7, 2023

  33. bitcoin locked this on Nov 6, 2024

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-04-15 18:13 UTC

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