← Back to Pull requests

Keep console_bridge's output handler and the loader mutex alive until the class loaders are destroyed #252

Closed
unknown closed this pull request without merging on Nov 28, 2026 02:30 UTC
View on GitHub
unknown unknown commented on Nov 21, 2026 22:24 UTC
Author

On macOS every process that still holds class loaders through MultiLibraryClassLoader at exit aborts (seen with rqt, e.g. rqt --list-plugins exits with code 134):

std::terminate()
class_loader::ClassLoader::~ClassLoader()
class_loader::ClassLoaderPtrVectorImpl::~ClassLoaderPtrVectorImpl()
__cxa_finalize_ranges
exit

The exception is std::system_error: mutex lock failed, thrown from console_bridge::log (called by CONSOLE_BRIDGE_logDebug in ~ClassLoader()): console_bridge's output handler, a function-local static with a mutex, has already been destroyed when the static ClassLoaderPtrVectorImpl destroys the remaining loaders.

ClassLoaderDependency already constructs class_loader's own statics before class_loader_ptrs_ so that they are destroyed after it. This adds console_bridge::getLogLevel() there, which constructs console_bridge's output handler first, so it is destroyed after the loaders as well.

Loader mutex (rolling): getLoaderMutex(), added for concurrent load and unload, is another function-local static that ~ClassLoader() uses: unloadLibrary() locks it. It wasn't constructed in ClassLoaderDependency() either, so with only the console_bridge fix, the same exit path still aborted, this time with recursive_mutex lock failed. This PR moves it out of the anonymous namespace, declares it in class_loader_core.hpp next to the other impl mutex accessors, and constructs it in ClassLoaderDependency() too.

Regression test: test/exit_order_test.cpp is its own executable, so none of these statics exist before the test runs. Its death test exits while a MultiLibraryClassLoader still holds a library. On macOS (arm64), with rolling at 6aff570:

  • Without the fixes: it fails with mutex lock failed.

  • With them: it passes.

  • On Linux, locking a destroyed mutex doesn't throw, so there it only checks that a process can exit with a live loader.
  • Other testing:

  • class_loader_utest and class_loader_external_load_test pass.

  • class_loader_unmanaged_test crashes (SIGSEGV) on macOS with and without this PR, so it's unrelated.

  • The uncrustify divergence reported for test/base.hpp also predates this PR.

  • Earlier, with jazzy's class_loader 2.7.1 plus the console_bridge change, rqt --list-plugins exits with 0 instead of aborting.
  • 🤖 Claude (AI assistant), on behalf of @Tobias-Fischer

    🤖 Generated with Claude Code

    Diff: 305 lines (+228 / -77) across 3 files Reviewer: mjcarroll Review duration: 8886m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 305 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.342
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #252"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 40.2% (MEDIUM) · Higher = larger blast radius
    40.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 15.9% · Safe to merge
    15.9%