Skip to content

branch-4.1: [fix](be) Fix SIGSEGV in bvar::take_sample caused by ~AgentCombiner walking freed TLS agents #67276 - #68045

Open
github-actions[bot] wants to merge 1 commit into
branch-4.1from
auto-pick-67276-branch-4.1
Open

github-actions[bot] wants to merge 1 commit into
branch-4.1from
auto-pick-67276-branch-4.1

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Cherry-picked from #67276

…alking freed TLS agents (#67276)

### What problem does this PR solve?

Issue Number: close #66895

Related PR: apache/brpc#3291

Problem Summary:

Follow-up to #64040 (backport of apache/brpc#2949). That fix made
`Agent::~Agent()`
safe by using a `weak_ptr` for `Agent::combiner`, but `~AgentCombiner()`
still calls
`clear_all_agents()`. When the last `shared_ptr` to the combiner is
released while
another thread is exiting, the TLS agents' `weak_ptr`s are already
expired: `~Agent`
skips `commit_and_erase()` and leaves its `LinkNode` in `_agents`, then
the
`ThreadBlock` is freed - and `clear_all_agents()` walks that freed TLS
storage,
causing a heap-use-after-free. In production this shows up as SIGSEGV in
`bvar::SeriesSampler::take_sample` (#66895).

Fix: port apache/brpc#3291 - `~AgentCombiner()` no longer traverses
`_agents`.
This is safe: `butil::LinkNode` has a trivial destructor and is never
dereferenced
when the list is torn down, and surviving agents observe
`combiner.expired() == true`
in `~Agent` and skip `commit_and_erase()`. There is no memory leak:
agents are freed
together with their `ThreadBlock` at thread exit. This closes the gap
that was
flagged during review of #64040.

### Release note

None

### Check List (For Author)

- Test
    - [ ] Regression test
    - [ ] Unit Test
    - [x] Manual test (add detailed scripts or steps below)
    - [ ] No need to test or manual test. Explain why:
- Behavior changed:
    - [x] No.
    - [ ] Yes.
- Does this need documentation?
    - [x] No.
    - [ ] Yes.

Manual test:

1. Applied the patch on top of the existing
`brpc-1.4.0-fix-agent-combiner-thread-safety.patch` and rebuilt brpc
1.4.0
   thirdparty + BE (4.1.3-based image).
2. Ran the same workload that previously triggered the crashes in
#66895:
   sustained high-EPS stream load while rewriting a ~40B-row table from
   storage format V2 to V3 on the affected production cluster
   (compute-storage coupled mode, 6 BE nodes, Kubernetes).
3. Before the fix: BEs crashed with SIGSEGV in
`bvar::SeriesSampler::take_sample` (two BEs independently, see issue).
After the fix: the production cluster has been running stable for 2 days
   with the patch applied - no recurrence of the SIGSEGV.

### Check List (For Reviewer who merge this PR)

- Confirm the release note
- Confirm test cases
- Confirm document
- Add branch pick label

Co-authored-by: stinger1206 <4540066+stinger1206@users.noreply.github.com>
@github-actions
github-actions Bot requested a review from yiguolei as a code owner September 16, 2026 02:53
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@hello-stephen

Copy link
Copy Markdown
Contributor

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 59.85% (25990/43428)
Line Coverage 44.57% (268413/602196)
Region Coverage 40.44% (213035/526832)
Branch Coverage 41.91% (98477/234970)

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.

2 participants