Skip to content

jazzy, lyrical, rolling: fix class_loader exit abort (console_bridge static order) - #243

Merged
Tobias-Fischer merged 2 commits into
mainfrom
class-loader-exit-order
Nov 22, 2026
Merged

Tobias-Fischer merged 2 commits into
mainfrom
class-loader-exit-order

Conversation

@Tobias-Fischer

@Tobias-Fischer Tobias-Fischer commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

On macOS, processes that still hold ClassLoaders at exit abort, for example rqt --list-plugins and closing rqt: mutex lock failed, then std::terminate and exit code 134.

Cause: class_loader's static ClassLoaderPtrVectorImpl destroys the remaining loaders at exit. ~ClassLoader() logs through console_bridge, whose output handler (a function-local static) has already been destroyed by then. ClassLoaderDependency() already makes sure class_loader's own statics outlive class_loader_ptrs_. Calling console_bridge::getLogLevel() there does the same for console_bridge's.

Fix: the same one-line change as ros/class_loader#252, as patch/ros2-class-loader.patch with build-number bumps:

distro class_loader build number
jazzy 2.7.1 32 (new patch)
lyrical 2.9.4 31
rolling 3.0.2 33
  • humble: class_loader 2.2.0 has no ClassLoaderDependency and doesn't abort, so it's unchanged.
  • lyrical and rolling: their previous ros2-class-loader.patch only made getAvailableClassesForLibrary's loader const. Upstream already has that in 2.9.4 and 3.0.2; on rolling, the old hunk applied with an offset to a different line. It's replaced by this fix.

rolling only (class_loader 3.0): 3.0 added another static, getLoaderMutex(), which serializes load and unload. It also wasn't in ClassLoaderDependency, so with only the console_bridge fix, ~ClassLoader() still aborted at exit, this time locking a destroyed recursive_mutex. The rolling patch moves getLoaderMutex() out of the anonymous namespace, declares it in class_loader_core.hpp, and calls it in ClassLoaderDependency() too.

Regression test: shared/tests/ros2-class-loader.yaml (unix) builds a small plugin and a program that loads it through a MultiLibraryClassLoader it never destroys, then checks that the program exits 0. On macOS it aborts with the published lyrical and rolling class_loader (exit 134) and passes with this PR's builds on jazzy, lyrical and rolling; humble's class_loader 2.2.0 passes too. On Linux it runs as a smoke test: locking a destroyed mutex doesn't throw there.

Tested on osx-arm64: built all three. rqt --list-plugins, run offscreen, exits with 134 using the published class_loader and 0 with the patched one, on lyrical and rolling. Jazzy was checked the same way earlier.

🤖 Generated with Claude Code

…l exit

On exit, class_loader's static ClassLoaderPtrVectorImpl destroys the still-held
ClassLoaders, and ~ClassLoader() logs through console_bridge, whose output handler (a
function-local static) can already be gone: "mutex lock failed", std::terminate, exit 134
(e.g. `rqt --list-plugins` on macOS). ClassLoaderDependency() already orders class_loader's
own statics before class_loader_ptrs_; console_bridge::getLogLevel() there does the same for
console_bridge's. Same change as ros/class_loader#252. humble's class_loader 2.2.0 has no
ClassLoaderDependency and doesn't abort.

lyrical/rolling: the previous patch only made getAvailableClassesForLibrary's loader const,
which upstream already has in 2.9.4/3.0.2 (on rolling it applied with an offset to another
occurrence); it is replaced by this fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

ABI check (linux-64)

jazzy linux-64: 2 can be bumped on their own
2 packages can be bumped on their own (compatible: 2)
package released → PR verdict details
class-loader 2.7.1 (build 31) → 2.7.1 compatible: no ABI change headers unchanged
rmf-utils 1.6.2 (build 31) → 1.6.2 compatible: no ABI change headers unchanged

Compared with the newest builds on https://conda.anaconda.org/robostack-jazzy/linux-64.

lyrical linux-64: **1 need their dependents rebuilt**, 6 can be bumped on their own
package released → PR verdict details
rmf-fleet-adapter-python 2.13.0 (build 30) → 2.13.0 soname: SONAME changed: rebuild the dependents libraries: rmf_adapter.cpython-314-x86_64-linux-gnu.so (soname)
rebuild 0 dependents (of 1 released dependents, these link to it): none
6 packages can be bumped on their own (compatible: 6)
package released → PR verdict details
class-loader 2.9.4 (build 30) → 2.9.4 compatible: no ABI change headers unchanged
rmf-fleet-adapter 2.13.0 (build 30) → 2.13.0 compatible: no ABI change headers unchanged
rmf-task-ros2 2.13.0 (build 30) → 2.13.0 compatible: no ABI change headers unchanged
rmf-traffic-ros2 2.13.0 (build 30) → 2.13.0 compatible: no ABI change headers unchanged
rmf-utils 1.8.1 (build 30) → 1.8.1 compatible: no ABI change headers unchanged
rmf-websocket 2.13.0 (build 30) → 2.13.0 compatible: no ABI change headers unchanged

Compared with the newest builds on https://repo.prefix.dev/robostack-lyrical/linux-64.

rolling linux-64: **1 need their dependents rebuilt**, 1 to review (changed headers), 5 can be bumped on their own
package released → PR verdict details
rmf-fleet-adapter-python 2.12.0 (build 32) → 2.12.0 soname: SONAME changed: rebuild the dependents libraries: rmf_adapter.cpython-314-x86_64-linux-gnu.so (soname)
rebuild 0 dependents (of 1 released dependents, these link to it): none
class-loader 3.0.2 (build 32) → 3.0.2 compatible: no ABI change 1 headers changed (check for layout/inline changes): class_loader/class_loader/multi_library_class_loader.hpp
5 packages can be bumped on their own (compatible: 5)
package released → PR verdict details
rmf-fleet-adapter 2.12.0 (build 32) → 2.12.0 compatible: no ABI change headers unchanged
rmf-task-ros2 2.12.0 (build 32) → 2.12.0 compatible: no ABI change headers unchanged
rmf-traffic-ros2 2.12.0 (build 32) → 2.12.0 compatible: no ABI change headers unchanged
rmf-utils 1.7.0 (build 32) → 1.7.0 compatible: no ABI change headers unchanged
rmf-websocket 2.12.0 (build 32) → 2.12.0 compatible: no ABI change headers unchanged

Compared with the newest builds on https://repo.prefix.dev/robostack-rolling/linux-64.

About this check

Each package this pull request built, compared with its newest released build (tools/abi_check.py, libabigail):

  • compatible / additions: the package can be bumped on its own;
  • soname / incompatible: the packages that depend on it need a rebuild (build number bump) in the same pull request.

Exported symbols are compared (the released packages are stripped, so struct layouts aren't); unchanged installed headers rule out layout and inline changes, changed ones are listed for review. Dependents to rebuild are the released ones linking to a changed library. A changed pin is part of the comparison.

@traversaro traversaro left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to go for me, but those are the classical issues that it is quite easy to regress on. If the agent could find a test that captures this problem so we make sure we do not regress, it would be great.

…the loader mutex alive

- shared/tests/ros2-class-loader.yaml: builds a small plugin and a program that loads it
  through a MultiLibraryClassLoader it never destroys, and checks that the program exits 0.
  Without the fix it aborts on macOS ("mutex lock failed", exit 134) with the published
  lyrical/rolling class_loader; it passes with this PR's builds on jazzy, lyrical and rolling
  (and with humble's 2.2.0).
- rolling (class_loader 3.0.2): the test also caught that 3.0's getLoaderMutex() (a static
  added for concurrent load/unload) isn't in ClassLoaderDependency either, so
  ~ClassLoader()'s unload at exit locked a destroyed recursive_mutex. It is now declared in
  class_loader_core.hpp and constructed in ClassLoaderDependency() as well.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Tobias-Fischer

Tobias-Fischer commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator Author

@traversaro, good call: the test found a second instance of the same bug.

I added shared/tests/ros2-class-loader.yaml. It builds a small plugin and a program that loads it through a MultiLibraryClassLoader that is never destroyed, then checks that the program exits cleanly. That's the situation behind the rqt abort, without needing rqt.

Results on osx-arm64:

  • Published lyrical and rolling class_loader: the test aborts with the original mutex lock failed (exit 134).
  • This PR's builds for jazzy, lyrical and rolling: it passes.
  • humble's class_loader 2.2.0: it passes too, so the test applies to every distro.

On Linux it runs as a smoke test only: locking a destroyed mutex doesn't throw there.

On rolling, the test caught a second instance. class_loader 3.0 added another static, getLoaderMutex(), which serializes load and unload, and it isn't in ClassLoaderDependency either. With only the console_bridge fix, ~ClassLoader() still aborted at exit, this time on a destroyed recursive_mutex. The rolling patch now constructs that mutex in ClassLoaderDependency() as well, and the test passes.

I haven't added that second fix to ros/class_loader#252 yet; it affects upstream rolling the same way.

🤖 Claude (AI assistant), on behalf of @Tobias-Fischer

@traversaro

Copy link
Copy Markdown
Member

Great, thanks!

@Tobias-Fischer
Tobias-Fischer enabled auto-merge (squash) November 22, 2026 16:35
@Tobias-Fischer
Tobias-Fischer merged commit 9a18c36 into main Nov 22, 2026
29 checks passed
@Tobias-Fischer
Tobias-Fischer deleted the class-loader-exit-order branch November 22, 2026 16:40
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