Skip to content

Never destroy class_loader's global state - #245

Merged
ahcorde merged 3 commits into
rollingfrom
mjcarroll/never-destroyed-globals
Dec 2, 2026
Merged

ahcorde merged 3 commits into
rollingfrom
mjcarroll/never-destroyed-globals

Conversation

@mjcarroll

@mjcarroll mjcarroll commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Description

Fixes #33.

A ClassLoader with static storage duration (e.g. a static pluginlib::ClassLoader) is usually destroyed after class_loader's function-local statics, so its destructor uses the already-destroyed library vector, factory maps and mutexes. The globals in class_loader_core.cpp are now allocated on first use and never destroyed, which also makes the MetaObjectGraveyardVector destructor workaround unnecessary.

Is this user-facing behavior change?

No.

Did you use Generative AI?

Claude Code (Claude Opus 5.5) wrote the change; I reviewed it.

Additional Information

Stacked on #244, the other half of #33; I'll retarget this to rolling once that merges. New death test ClassLoaderStaticTest.staticLoadersDestroyedAtExit fails under ASan without the fix.

@mjcarroll mjcarroll self-assigned this Nov 10, 2026
@mjcarroll
mjcarroll marked this pull request as draft November 10, 2026 03:29
@mjcarroll
mjcarroll force-pushed the mjcarroll/never-destroyed-globals branch 2 times, most recently from f124805 to 840bffa Compare November 28, 2026 04:03
@mjcarroll
mjcarroll force-pushed the mjcarroll/never-destroyed-globals branch from 48bed34 to 0cab695 Compare November 28, 2026 04:05
@mjcarroll
mjcarroll marked this pull request as ready for review November 28, 2026 13:28
@mjcarroll
mjcarroll requested a review from ahcorde November 28, 2026 13:28
@mjcarroll
mjcarroll added this pull request to stack #256 December 1, 2026 19:13
@mjcarroll
mjcarroll force-pushed the mjcarroll/never-destroyed-globals branch from 38a716d to cd44da7 Compare December 1, 2026 19:19
@mjcarroll

Copy link
Copy Markdown
Member Author

Pulls: #245
Branch: mjcarroll/never-destroyed-globals
BUILD args: --packages-above-and-dependencies class_loader
TEST args: --packages-above class_loader
ROS Distro: rolling
Job: ci_launcher
ci_launcher ran: https://ci.ros2.org/job/ci_launcher/21426

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

Base automatically changed from mjcarroll/multi-loader-ownership to rolling December 2, 2026 08:25
mjcarroll and others added 3 commits December 2, 2026 09:25
A ClassLoader or MultiLibraryClassLoader with static storage duration,
such as a static pluginlib::ClassLoader, is usually created before
class_loader's function-local static globals, so it is destroyed after
them at exit. Its destructor then unloads its libraries using the
already-destroyed library vector, factory maps and mutexes.

Allocate the globals on first use and never destroy them. This also
makes the MetaObjectGraveyardVector destructor workaround unnecessary.

Fixes #33

Signed-off-by: Michael Carroll <[email protected]>
A MultiLibraryClassLoader and a ClassLoader with static storage duration
are destroyed at exit, after the globals first touched by loadLibrary().
Without ASan this is only flaky, so the test is meant to be run under it.

Signed-off-by: Michael Carroll <[email protected]>
The lazy ClassLoader unloaded its library inside main() when its
instance was released, so its exit path was never tested. Load it
explicitly instead, so ~ClassLoader unloads it at exit. Remove the
death test: its non-lazy loader created the globals first, so it
passed without the fix.

Signed-off-by: Alejandro Hernandez Cordero <[email protected]>
@ahcorde
ahcorde force-pushed the mjcarroll/never-destroyed-globals branch from cd44da7 to aeeeece Compare December 2, 2026 08:25
@ahcorde
ahcorde merged commit 7529400 into rolling Dec 2, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

usage of multiple static variables is discouraged

2 participants