Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pthread mutex deadlock detection #2692

Merged
merged 2 commits into from
Jul 19, 2024

Conversation

chenBright
Copy link
Contributor

@chenBright chenBright commented Jul 13, 2024

What problem does this PR solve?

Issue Number:

Problem Summary:

线程锁临界区内挂起协程(bthread_mutex、sync rpc、bthread_usleep、bthread_yield等),属于未定义行为(大概率会造成死锁)。目前缺少一种发现机制,只能等到出现死锁后查看调用栈再排查。

What is changed and the side effects?

Changed:

brpc已经hook了pthread mutex接口,加锁的时候将线程局部变量加一,解锁的时候,将线程局部变量减一。只有在线程局部变量等于0的时候,挂起协程才是安全的,否则,将调用栈打印出来用于排查问题。该调用栈只打印一次,因为一旦出现pthread mutex临界区内挂起协程,线程局部变量已经是错乱的,后续的调用栈已经没有参考价值。

Side effects:

  • Performance effects(性能影响):

  • Breaking backward compatibility(向后兼容性):


Check List:

  • Please make sure your changes are compilable(请确保你的更改可以通过编译).
  • When providing us with a new feature, it is best to add related tests(如果你向我们增加一个新的功能, 请添加相关测试).
  • Please follow Contributor Covenant Code of Conduct.(请遵循贡献者准则).

@chenBright chenBright force-pushed the detect_deadlock branch 5 times, most recently from 30a1bf0 to c97b9d3 Compare July 13, 2024 17:47
@chenBright chenBright changed the title Support pthread deadlock detection Support pthread mutex deadlock detection Jul 14, 2024
src/bthread/mutex.cpp Outdated Show resolved Hide resolved
@wwbmmm
Copy link
Contributor

wwbmmm commented Jul 16, 2024

LGTM

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.

3 participants