Repository navigation
Keep console_bridge's output handler and the loader mutex alive until the class loaders are destroyed - #252
Open
Tobias-Fischer wants to merge 2 commits into
Open
Tobias-Fischer wants to merge 2 commits into
Tobias-Fischer wants to merge 2 commits into
Conversation
…e destroyed ~ClassLoader() logs through CONSOLE_BRIDGE_logDebug. ClassLoaders still held by MultiLibraryClassLoader live in the function-local static of getClassLoaderPtrVectorImpl() and are destroyed at exit. On macOS console_bridge's output handler (also a function-local static, with a mutex) can be destroyed before that, so the log call locks a destroyed mutex, throws std::system_error from a destructor and the process aborts on exit (e.g. every rqt exit). ClassLoaderDependency already constructs class_loader's own statics first so that they outlive class_loader_ptrs_; construct console_bridge's output handler there too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Tobias Fischer <info@tobiasfischer.info>
…d a regression test
getLoaderMutex() (added with the concurrent load/unload fix) is another function-local
static that ~ClassLoader() uses: unloadLibrary() locks it. It wasn't constructed in
ClassLoaderDependency(), so it could be destroyed before class_loader_ptrs_ and
~ClassLoader() then locked a destroyed recursive_mutex at exit ("recursive_mutex lock
failed", std::terminate on macOS). Declare it in class_loader_core.hpp and construct it in
ClassLoaderDependency() like the other statics.
exit_order_test (own executable, so none of these statics exist beforehand) exits in a death
test while a MultiLibraryClassLoader still holds a library. Without these fixes it aborts on
macOS ("mutex lock failed").
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tobias Fischer <info@tobiasfischer.info>
Author
|
I've pushed a second commit: the loader mutex fix and a regression test. Writing the regression test exposed a second static with the same problem. 🤖 Claude (AI assistant), on behalf of @Tobias-Fischer |
Tobias-Fischer
added a commit
to RoboStack/robostack
that referenced
this pull request
Nov 22, 2026
…static order) (#243) * jazzy, lyrical, rolling: class_loader keeps console_bridge alive until 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> * class_loader: regression test for the exit order; rolling also keeps 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> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On macOS every process that still holds class loaders through
MultiLibraryClassLoaderat exit aborts (seen withrqt, e.g.rqt --list-pluginsexits with code 134):The exception is
std::system_error: mutex lock failed, thrown fromconsole_bridge::log(called byCONSOLE_BRIDGE_logDebugin~ClassLoader()): console_bridge's output handler, a function-local static with a mutex, has already been destroyed when the staticClassLoaderPtrVectorImpldestroys the remaining loaders.ClassLoaderDependencyalready constructs class_loader's own statics beforeclass_loader_ptrs_so that they are destroyed after it. This addsconsole_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 inClassLoaderDependency()either, so with only the console_bridge fix, the same exit path still aborted, this time withrecursive_mutex lock failed. This PR moves it out of the anonymous namespace, declares it inclass_loader_core.hppnext to the other impl mutex accessors, and constructs it inClassLoaderDependency()too.Regression test:
test/exit_order_test.cppis its own executable, so none of these statics exist before the test runs. Its death test exits while aMultiLibraryClassLoaderstill holds a library. On macOS (arm64), with rolling at 6aff570:mutex lock failed.Other testing:
test/base.hppalso predates this PR.rqt --list-pluginsexits with 0 instead of aborting.🤖 Claude (AI assistant), on behalf of @Tobias-Fischer
🤖 Generated with Claude Code