Fix lock-order inversion deadlock in Diags::tag_activated#13106
Merged
Conversation
This fixes a deadlock between Diags::tag_table_lock and the dynamic loader lock. The issue occurs when Regex::exec() lazily constructs a thread_local RegexContext whose destructor registration via __cxa_thread_atexit_impl acquires the dl loader lock. Holding tag_table_lock across exec() creates a lock-order inversion with dlopen() callers that construct a DbgCtl during plugin static initialization (which takes tag_table_lock while already holding the dl loader lock). This changes activated_tags to use std::shared_ptr<Regex> and snapshots the regex under the lock before releasing it and calling exec(). The same pattern is applied to activate_taglist() which now compiles the new regex outside the lock. Fixes: apache#13101
cmcfarlen
approved these changes
Apr 23, 2026
Contributor
|
Cherry-picked to 10.2.x |
cmcfarlen
pushed a commit
that referenced
this pull request
Apr 29, 2026
(cherry picked from commit 571ee72)
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.
This fixes a deadlock between Diags::tag_table_lock and the dynamic loader lock. The issue occurs when Regex::exec() lazily constructs a thread_local RegexContext whose destructor registration via __cxa_thread_atexit_impl acquires the dl loader lock. Holding tag_table_lock across exec() creates a lock-order inversion with dlopen() callers that construct a DbgCtl during plugin static initialization (which takes tag_table_lock while already holding the dl loader lock).
This changes activated_tags to use std::shared_ptr and snapshots the regex under the lock before releasing it and calling exec(). The same pattern is applied to activate_taglist() which now compiles the new regex outside the lock.
Fixes: #13101