apache / apache/brpc

Span::CreateClientSpan是否有线程安全问题

Open
#2,315 14 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C++
Stars
17.6k
Forks
4.1k
Avg merge
2d 12h
Merged PRs (30d)
69

Description

**Describe the bug (描述bug)**

https://github.com/apache/brpc/blob/master/src/brpc/span.cpp#L133
image

在代码这个位置,如果是在多个bthread中调用的Span::CreateClientSpan,而他们属于同一个Span的child span。此时他们对brpc::Span::_next_client是存在竞态的。
即便认为这个指针的赋值是原子的,似乎也可能导致内存泄漏。

这里是有什么特殊的设计避免了竞态吗?求解答

**To Reproduce (复现方法)**

**Expected behavior (期望行为)**

**Versions (各种版本)**
OS:
Compiler:
brpc:
protobuf:

**Additional context/screenshots (更多上下文/截图)**

Contributor guide

Open the contributing guide

Research direction

Start at src/brpc/span.cpp#L133 and trace how concurrent bthreads call Span::CreateClientSpan when sharing a parent Span. Inspect accesses to brpc::Span::_next_client, then determine whether the pointer update can race or leak memory. Done means the thread-safety question is resolved with evidence from the implementation and a focused concurrency reproduction.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
distributed-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.