Fix initialization order problem with numCommandsTargetingSystemBuckets

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Major - P3
    • 9.1.0-rc0, 9.0.0-rc2
    • Affects Version/s: 9.0.0-rc0, 8.3.0
    • Component/s: None
    • None
    • Catalog and Routing
    • Fully Compatible
    • ALL
    • v9.0, v8.3
    • Hide

      Spawn a windows machine and populate it with windows mongod binaries. Call the windows binary as a service rather than directly

      C:\Users\Administrator> C:\Users\Administrator\dist-test\bin\mongod.exe --dbpath C:\mongo-rs0\db --logpath C:\mongo-rs0\log\mongod.log --logappend --port 27017 --replSet rs0 --bind_ip 127.0.0.1 --install --serviceName MongoRS0 --serviceDisplayName MongoRS0 
      C:\Users\Administrator> net start MongoRS0
      Show
      Spawn a windows machine and populate it with windows mongod binaries. Call the windows binary as a service rather than directly C:\Users\Administrator> C:\Users\Administrator\dist-test\bin\mongod.exe --dbpath C:\mongo-rs0\db --logpath C:\mongo-rs0\log\mongod.log --logappend --port 27017 --replSet rs0 --bind_ip 127.0.0.1 --install --serviceName MongoRS0 --serviceDisplayName MongoRS0 C:\Users\Administrator> net start MongoRS0
    • CAR Team 2026-08-03
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      The `numCommandsTargetingSystemBuckets` metric is initialized differently to most metrics. While most metrics are registered at file scope, this metric is initialized during the constructor of the SystemBucketsMetricsCommandHooks. That constructor runs when initializeCommandHooks() builds MongodCommandInvocationHooks which is called from _initAndListen().

      This triggers an invariant on Windows when the mongod binary is run as a service because metrics are required to all be registered on the main thread. In this mode, rather than main() calling _initAndListen directly, main() calls ntservice::startService(), which uses StartServiceCtrlDispatcherW. That hands off to the SCM service thread, meaning that the timeseries metric is registered from a different thread than the main thread, thus triggering the invariant. We have never seen this in the server testing corpus because we never run windows binaries in this way.

            Assignee:
            Allison Easton
            Reporter:
            Allison Easton
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: