apache / apache/brpc

一个被interrupt的bthread,总是sleep()成功,导致无法从sleep()退出.

Open
#721 1 comment 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)**
如下的bthread无法退出:
一个thread 周期性的发rpc,可能无法被stop后join。
原因是bthread_usleep永远成功。
```
1 void thread_hang() {
2 while(true) {
3
4 // Issue rpc.
5 channel.CallMethod(null, cntl, ....);
6 if (cntl.Failed()) {
7 ....
8 }
9
10 if (bthread_usleep() < 0) {
11 if (errno == ESTOP) {
12 break;
13 }
14 break;
15 }
16 }
17 }
18
19
20 void other_thread() {
21 bthread_start(&bth, thread_hang(),..);
22
23 .....
24
25 bthread_stop(bth);
26 bthread_join(bth, nullptr); // Hang up here
27 }

```

**Expected behavior (期望行为)**
上面的形式的bthread不能够正常退出。目前的WA是通过bthread_stopped()来判断退出。
rpc的处理回复的流程Join(correlation_id) -> bthread_id_join() -> bthread::butex_wait()。在butex_wait()中会对于被interrupt的bthread会有如下操作:
标记bbw.task_meta->interrupted = false; 设置错误码为EINTR

而int TaskGroup::usleep(TaskGroup** pg, uint64_t timeout_us) 对于interrupted==false 直接返回成功,导致一个被interrupt的bthread总是sleep成功。

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.