Improve metric lifetime semantics and 'MetricsService::clearForTests()'

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Fixed
    • Priority: Major - P3
    • 9.0.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Networking & Observability
    • Fully Compatible
    • N&O 2026-05-11
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Spun out from SERVER-123982. There I added some strange behavior to MetricsService to allow external callers to own the metrics. This was due to server_status_servers_test.cpp calling 'clearForTests()', which would delete the unique_ptrs that I wanted to capture as global variables. The test would then cause segfaults whenever a command ran and tried to increment the global opCounters which pointed to the previous metrics service instantiation (deleted), a use after free.

       

      mike.nugent@mongodb.com suggested this could be improved and simplified.

            Assignee:
            Michael Nugent
            Reporter:
            Charlie Swanson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: