Skip to content

Fix lock-order inversion deadlock in Diags::tag_activated#13106

Merged
bneradt merged 1 commit into
apache:masterfrom
bneradt:fix_dbctl_deadlock
Apr 23, 2026
Merged

Fix lock-order inversion deadlock in Diags::tag_activated#13106
bneradt merged 1 commit into
apache:masterfrom
bneradt:fix_dbctl_deadlock

Conversation

@bneradt
Copy link
Copy Markdown
Contributor

@bneradt bneradt commented Apr 20, 2026

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

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
@bneradt bneradt added this to the 11.0.0 milestone Apr 20, 2026
@bneradt bneradt requested a review from cmcfarlen April 20, 2026 18:32
@bneradt bneradt self-assigned this Apr 20, 2026
@bneradt bneradt added the Bug label Apr 20, 2026
@bneradt bneradt merged commit 571ee72 into apache:master Apr 23, 2026
15 checks passed
@bneradt bneradt deleted the fix_dbctl_deadlock branch April 23, 2026 23:06
@github-project-automation github-project-automation Bot moved this to For v10.2.0 in ATS v10.2.x Apr 23, 2026
@cmcfarlen cmcfarlen moved this from For v10.2.0 to Picked v10.2.0 in ATS v10.2.x Apr 28, 2026
@cmcfarlen cmcfarlen modified the milestones: 11.0.0, 10.2.0 Apr 28, 2026
@cmcfarlen
Copy link
Copy Markdown
Contributor

Cherry-picked to 10.2.x

cmcfarlen pushed a commit that referenced this pull request Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Picked v10.2.0

Development

Successfully merging this pull request may close these issues.

Startup deadlock between dlopen() of remap plugins and Diags::tag_activate_lock via UDP thread (ASan-built 10.2.x)

2 participants