Use RTLD_NODELETE when loading the render engine plugin (backport #1280)#1287
Merged
iche033 merged 1 commit intogz-rendering9from Apr 30, 2026
Merged
Use RTLD_NODELETE when loading the render engine plugin (backport #1280)#1287iche033 merged 1 commit intogz-rendering9from
iche033 merged 1 commit intogz-rendering9from
Conversation
Repeated unloadEngine/engine cycles dlopen and dlclose the engine plugin. Some transitive dependency (libgomp on Ubuntu Noble + rotary nightly packages) uses thread-local storage; without RTLD_NODELETE, each reload allocates from glibc's static-TLS surplus, which is not reliably reclaimed on dlclose. After ~10 cycles the surplus is exhausted and the next dlopen fails with "cannot allocate memory in static TLS block" Pass _noDelete=true to gz-plugin's Loader::LoadLib so dlclose keeps the library mapped. TLS is allocated once on first load and reused on every subsequent reload, eliminating the leak. Trade-off: the plugin and its transitive deps remain resident for the lifetime of the process. For a rendering engine this is the expected lifetime anyway. Fixes #1265 Generated-by: Claude Opus 4.7 Signed-off-by: Taylor Howard <taylorhoward@me.com> (cherry picked from commit fb9dd4c)
11 tasks
iche033
approved these changes
Apr 30, 2026
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.
🦟 Bug fix
Fixes #1265
Summary
Repeated
unloadEngine/enginecycles dlopen and dlclose the engine plugin. A transitive dependency in the plugin's chain (libgompon Ubuntu Noble + rotary nightly packages, vialibgz-common-graphics→libassimpand friends) uses thread-local storage. WithoutRTLD_NODELETE, each reload allocates from glibc's static-TLS surplus, which is not reliably reclaimed ondlclose. After ~10 cycles the surplus is exhausted and the nextdlopenfails with:This regression appeared on
mainafter #1246 switched CI to the rotary alias packages, which (via thegz-commonrebuild that swapped FreeImage for vendored STB ingz-common#803) no longer transitively pulllibfreeimage→libraw→libgompinto the test binary's startupDT_NEEDED. The static-TLS exhaustion was latent before that change —libfreeimage's dep chain was anchoringlibgompin the main binary's TLS region for free.The fix passes
_noDelete=truetogz::plugin::Loader::LoadLib, which gates theRTLD_NODELETEflag that's already supported by gz-plugin's loader. With this flag,dlclosekeeps the library mapped, finalizers don't run, andTLS slots aren't released. TLS is allocated once on first load and reused on every subsequent reload, eliminating the surplus leak regardless of which library in the plugin's chain is the TLS hog.
Reproduction
REGRESSION_reload_engine_ogre2_gl3plusreproduces the failure 100% of the time inside a freshubuntu:nobledocker container withgzdev repository enable --project=rotary(matching whatgazebo-tooling/action-gz-ci@nobledoes). Before this PR: 5 cases fail with the static-TLS error. After this PR: 8/8 cases pass.Trade-off
The engine plugin and its transitive dependencies remain mapped for the lifetime of the process. For a rendering engine this is effectively the process's lifetime anyway,
Ogre::Rootis created and destroyed byOgre2RenderEngineat the C++ level, separately from library load/unload, so callingunloadEnginefollowed byengine()still produces a freshOgre::Root. What changes:Alternatives considered
-Wl,--no-as-needed -lgompinto the test executable (initial attempt): works but only patches the test, doesn't fix the underlying reload bug for downstream consumers, GCC-specific, and only handles libgomp.GLIBC_TUNABLES=glibc.rtld.optional_static_tls=N: runtime-only, delays exhaustion rather than fixing it, and requires CI-environment plumbing.NEEDEDchain: the chain is largely load-bearing (the plugin uses ~80 symbols fromlibgz-common-graphics); not a productive direction.RTLD_NODELETEis the only option that fixes the bug for everygz::rendering::engine()consumer and not just this one test.Checklist
codecheckpassed (See contributing)ubuntu:nobledocker container withgzdevrotary packages, the previously-failingREGRESSION_reload_engine_ogre2_gl3plusnow passes (5.18 s, 8/8 cases).Generated-by: Claude Code
Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining
Signed-off-byandGenerated-bymessages.This is an automatic backport of pull request #1280 done by Mergify.