Repository navigation
Construct the loader mutex before the static loader vector - #253
Conversation
impl::unloadLibrary() locks getLoaderMutex() first. ClassLoaderDependency only forces the other function-local statics to be constructed before the static ClassLoaderPtrVectorImpl, so when a MultiLibraryClassLoader is the first user of class_loader, the loader mutex is first used after that static was constructed and is destroyed before it. The vector's destructor then destroys a ClassLoader, which locks the destroyed mutex and aborts at exit with "recursive_mutex lock failed: Invalid argument". Construct it from getLoadedLibraryVectorMutex(), which the dependency already forces, and add a regression test that keeps a loader alive until static destruction. Signed-off-by: Michael Carroll <mjcarroll.oss@gmail.com>
14e37b5 to
30f81dc
Compare
| namespace | ||
| { | ||
| std::recursive_mutex & getLoaderMutex(); | ||
| } // namespace |
There was a problem hiding this comment.
Rather than forward-declaring it like this, can we just move the getLoaderMutex block down below up here?
|
Pulls: #253 |
Signed-off-by: Michael Carroll <mjcarroll.oss@gmail.com>
clalancette
left a comment
There was a problem hiding this comment.
Looks good with green CI.
|
Pulls: #253 |
…clcpp#3430); give class_loader's new multi_library_exit_test its own cc_test
Description
impl::unloadLibrary()locksgetLoaderMutex()first, butClassLoaderDependencydoes not force it to be constructed before the staticClassLoaderPtrVectorImpl. If aMultiLibraryClassLoaderis the first user of class_loader, the mutex is destroyed before the vector, whose destructor then destroys aClassLoaderthat locks it, and the process aborts at exit (recursive_mutex lock failed: Invalid argument).Construct it from
getLoadedLibraryVectorMutex(), which the dependency already forces. Adds a regression test (separate executable, loader kept alive until static destruction); it fails without the fix.Is this user-facing behavior change?
No.
Did you use Generative AI?
Yes, Claude Code (Claude Sonnet 5.5) was used to find the cause, write the fix and test.
Additional Information
Found while running the ROS 2 test suites under Bazel with libc++, where
image_transportandpoint_cloud_transporttests crashed at exit.