Repository navigation
Conversation
rcl_logging_implementation unloads the logging library from an atexit() handler, but objects that the library creates can outlive that handler and run its code later in exit(). rcl_logging_spdlog starts spdlog's periodic flush thread and registers its logger with spdlog. In a process that uses spdlog itself, spdlog's registry is created before the handler is registered, so its static destructors run after it: they stop the flush thread and destroy the logger after the library is gone, and the process dies with SIGSEGV after main() has returned, with or without rcl_logging_external_shutdown(). When rcl linked the logging implementation directly, it was never unloaded. Keep the library loaded until the process exits. The tests still unload it with force_unload_logging_library() to switch implementations. Add test_exit_with_spdlog: a process that uses spdlog logs through rcl_logging_spdlog and exits, after a shutdown and without one. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Juan Pablo Pino Bravo <[email protected]>
Author
|
Closing in favour of #150, which makes the same change and came first. The crash this PR was about, and its test, are described there: #150 (comment) |
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.
Since the logging implementation is loaded at runtime, a process that uses spdlog itself and logs through
rcl_logging_spdlogdies with SIGSEGV (exit code 139) aftermain()has returned. That happens with or withoutrclcpp::shutdown(), so it hits every node of a program that also uses spdlog for its own logging.Cause
rcl_logging_implementationunloads the logging library from anatexit()handler, which it registers when logging is first initialized.rcl_logging_spdlogstarts spdlog's periodic flush thread withspdlog::flush_every()and registers its logger with spdlog. That code lives in the plugin:flush_every()and theperiodic_workerconstructor are templates, and the plugin creates the sink.rclcpp::init(), spdlog's registry is created before the handler is registered, so its static destructors run after the handler. They stop the flush thread and destroy the logger after the library is gone.rcllinked the logging implementation directly, the implementation was never unloaded.Fix
g_logging_libis never destroyed, and there's noatexit()handler any more.rcl_logging_external_shutdown()already keeps the library loaded "to avoid race conditions".force_unload_logging_library()to switch implementations.Test
test_exit_with_spdloguses death tests. A child process that uses spdlog logs throughrcl_logging_spdlogand exits, once afterrcl_logging_external_shutdown()and once without it.It's its own executable because the other tests unload the library between tests. That isn't safe once spdlog outlives the library: the flush thread from one test would crash the next.
Tested against Lyrical's packages (Ubuntu 26.04, arm64, libspdlog 1.15.3):
TestExitWithSpdlog.exit_after_shutdownTestExitWithSpdlog.exit_without_shutdownWith the fix, all of the package's tests and linters pass (41 tests, 5 skipped).
The same change on Lyrical's 3.4.1, with the stock
rcl_logging_spdlog, makes our programs exit cleanly too: exit code 0 in 20 of 20 runs, with and without shutdown, against 139 before. So we'd like to ask for a backport tolyrical.🤖 Generated with Claude Code