Skip to content

Have MultiLibraryClassLoader instances keep their ClassLoader alive - #244

Merged
ahcorde merged 2 commits into
rollingfrom
mjcarroll/multi-loader-ownership
Dec 2, 2026
Merged

ahcorde merged 2 commits into
rollingfrom
mjcarroll/multi-loader-ownership

Conversation

@mjcarroll

@mjcarroll mjcarroll commented Nov 9, 2026 •

Copy link
Copy Markdown
Member

Description

MultiLibraryClassLoader kept its ClassLoaders in a process-wide static vector. Loaders whose instances outlived the MultiLibraryClassLoader were never released, so their libraries were never unloaded, and a static MultiLibraryClassLoader read that vector after it was destroyed at exit (part of #33).

Each MultiLibraryClassLoader now owns its loaders as shared_ptrs, and each instance it creates holds a shared_ptr to its loader. This removes the static vector and the ClassLoaderDependency workaround.

Is this user-facing behavior change?

No API change. ABI changes, so rolling only.

Did you use Generative AI?

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

Additional Information

Follow-up to #240. New test MultiClassLoaderTest.instanceOutlivesLoader; its non-lazy cases fail on rolling.

@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/multi-loader-ownership branch from 60da3c9 to 07a96dd Compare November 16, 2026 19:41
@mjcarroll
mjcarroll marked this pull request as ready for review November 16, 2026 19:47
@mjcarroll

Copy link
Copy Markdown
Member Author

Pulls: #244
Gist: https://gist.githubusercontent.com/mjcarroll/2f347ac03d76952b2bc41bf2e70999a8/raw/a9da9d853f0afe944ac01120bf46fb5cea8fcd40/ros2.repos
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/21133

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

@mjcarroll

Copy link
Copy Markdown
Member Author

Pulls: #244
Gist: https://gist.githubusercontent.com/mjcarroll/2e9362558194c9318b225c078fb53b20/raw/a9da9d853f0afe944ac01120bf46fb5cea8fcd40/ros2.repos
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/21164

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

@mjcarroll
mjcarroll force-pushed the mjcarroll/multi-loader-ownership branch from 07a96dd to e35c665 Compare November 28, 2026 03:09
MultiLibraryClassLoader kept every ClassLoader it created in a
process-wide static vector so loaders survived while their instances
were alive. Loaders whose instances outlived the MultiLibraryClassLoader
stayed there until process exit, and without on-demand unloading their
libraries were never unloaded.

Own the loaders per MultiLibraryClassLoader instead, and have each
instance hold a shared_ptr to its ClassLoader. A loader now lives
exactly as long as its MultiLibraryClassLoader or its last instance,
and the static vector and its destruction-order workaround go away.

Signed-off-by: Michael Carroll <[email protected]>
@mjcarroll
mjcarroll force-pushed the mjcarroll/multi-loader-ownership branch from e35c665 to ef2608a Compare November 28, 2026 04:05
@mjcarroll
mjcarroll requested a review from ahcorde November 28, 2026 13:28
Create class_loader's global data when the library is loaded, so it
outlives static loaders and instances destroyed at exit. Rewrite the
exit test to cover both cases. Don't unload loaders that still have
instances when a MultiLibraryClassLoader is destroyed; their last
instance unloads the library, without the "SEVERE WARNING".

Signed-off-by: Alejandro Hernandez Cordero <[email protected]>
@ahcorde

ahcorde commented Nov 30, 2026

Copy link
Copy Markdown
Contributor
  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

@ahcorde

ahcorde commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Pulls: #244
Gist: https://gist.githubusercontent.com/ahcorde/4bef1843339607be435ec95beb30d0c2/raw/a9da9d853f0afe944ac01120bf46fb5cea8fcd40/ros2.repos
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/21402

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

@mjcarroll

Copy link
Copy Markdown
Member Author

CI Test Results

Platform Result Failed Passed Skipped Duration Report
Linux ❌ fail 3 20446 399 169m 19s results
Linux-aarch64 ⚪ N/A — — — — results
Linux-rhel ✅ pass 0 18991 255 198m 54s results
Windows ❌ fail 3 18694 576 339m 42s results
Linux — 3 failure(s)
Package Test
CTest test_wait_set__rmw_connextdds
test_rmw_implementation.TestWaitSetSharedEntity guard_condition_in_two_wait_sets
test_rmw_implementation.TestWaitSetSharedEntity subscription_in_two_wait_sets
Windows — 3 failure(s)
Package Test
CTest test_wait_set__rmw_connextdds
test_rmw_implementation.TestWaitSetSharedEntity guard_condition_in_two_wait_sets
test_rmw_implementation.TestWaitSetSharedEntity subscription_in_two_wait_sets

@mjcarroll

Copy link
Copy Markdown
Member Author

Update to the CI table above: the aarch64 build there (#24246) lost its agent and was restarted as #24255: 3 failed, 20562 passed.

The failures are the same 3 as on Linux and Windows, all in rmw (test_wait_set__rmw_connextdds, TestWaitSetSharedEntity.guard_condition_in_two_wait_sets and subscription_in_two_wait_sets). None are class_loader tests. rhel passed.

@mjcarroll
mjcarroll added this pull request to stack #256 December 1, 2026 19:13
@ahcorde
ahcorde merged commit ccf77fa into rolling Dec 2, 2026
9 checks passed
@ahcorde
ahcorde deleted the mjcarroll/multi-loader-ownership branch December 2, 2026 08:25
mjcarroll added a commit to mjcarroll/rcr-nightly that referenced this pull request Dec 2, 2026
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.

2 participants