Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-102662

Add clarifying code comments to ScopeGuard / ON_BLOCK_EXIT()

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Trivial - P5 Trivial - P5
    • 8.2.0-rc0, 8.1.0-rc2
    • Affects Version/s: None
    • Component/s: None
    • None
    • Server Programmability
    • Fully Compatible
    • Programmability 2025-03-31, Programmability 2025-04-14
    • None
    • 0
    • None
    • None
    • None
    • None
    • None
    • None

      Users of the ON_BLOCK_EXIT macro may not be aware that the callback function they are passing to it runs in a noexcept context, and that any exception escaping from it will terminate the process.
      While it is clear when writing a destructor that it is implicitly noexcept and that exceptions should be handled, it is less clear when writing code using the ON_BLOCK_EXIT macro. SERVER-100707 is a real world issue that led to a server crash because an exception escaped an ON_BLOCK_EXIT callback function. There may be more such issues.

      We could improve on this by adding code comments to both the ScopeGuard class and the ON_BLOCK_EXIT macro, stating that the callback function will run in a noexcept context and that callers are responsible for handling exceptions in their callback function, and failure to do so will result in process termination.

            Assignee:
            billy.donahue@mongodb.com Billy Donahue
            Reporter:
            jan.steemann@mongodb.com Jan Steemann
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: