Skip to content

Fix stale AgentGroup TLS access after bthread migration - #3522

Open
bobhan1 wants to merge 1 commit into
apache:masterfrom
bobhan1:fix-3520-agent-group-tls-access
Open

Fix stale AgentGroup TLS access after bthread migration#3522
bobhan1 wants to merge 1 commit into
apache:masterfrom
bobhan1:fix-3520-agent-group-tls-access

Conversation

@bobhan1

@bobhan1 bobhan1 commented Sep 4, 2026

Copy link
Copy Markdown

What problem does this PR solve?

Issue Number: resolve #3520

Problem Summary:

bvar::detail::AgentGroup directly accesses the raw _s_tls_blocks thread-local variable from inline functions. When a bthread suspends and resumes on another pthread, Clang may reuse the TLS address resolved for the previous pthread. This can make bvar access another pthread's agent vector and race with its initialization or resize.

What is changed and the side effects?

Changed:

  • Declare _s_tls_blocks with the existing static-member volatile TLS accessor mechanism.
  • Resolve the current pthread's TLS block vector once in each AgentGroup operation and consistently use that pointer.
  • Route TLS initialization and cleanup writes through the existing setter accessor.

Side effects:

  • Performance effects: On compiler targets where volatile TLS access is enabled, AgentGroup operations use the existing noinline TLS accessor to prevent the TLS address from being retained across a bthread suspend point. Other targets retain direct TLS access through the existing macros.
  • Breaking backward compatibility: None.

Check List:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bvar] AgentGroup may use a stale _s_tls_blocks address after bthread migration under Clang

1 participant