imdouyu opened a new issue, #3240:
URL: https://github.com/apache/brpc/issues/3240
**Describe the bug**
``` C++
bool ExecuteTasks(const JobRequestPtr& job, int timeout_ms, int
worker_thread_num) {
bool status = true;
std::vector<bool> results(shard_count_, true;
std::vector<brpc::Controller> controllers(shard_count_);
std::vector<bthread_id_t> task_ids(shard_count_, INVALID_BTHREAD_ID);
std::shared_ptr<boost::asio::thread_pool> worker_pool = nullptr;
if (worker_thread_num > 1) {
worker_pool.reset(new
decltype(worker_pool)::element_type(worker_thread_num),
[](decltype(worker_pool)::element_type* pool) {
pool->join(); });
}
for (size_t idx = 0; idx < shard_count_; idx++) {
auto task = [&, idx]() {
auto shard_task = job->GetShardTask(idx);
auto worker = std::atomic_load(&workers_.at(idx));
if (worker == nullptr) {
task_ids[idx] = INVALID_BTHREAD_ID;
results[idx] = false;
return;
}
worker->Execute(&controllers[idx], shard_task, nullptr,
brpc::DoNothing(), 5000);
task_ids[idx] = controllers[idx].call_id();
};
if (worker_pool) {
boost::asio::post(*worker_pool, task);
} else {
task();
}
}
if (worker_pool) {
worker_pool->join();
}
for (size_t shard_idx = 0; shard_idx < shard_count_; shard_idx++) {
if (!results[shard_idx]) {
status = results[shard_idx];
}
if (task_ids.at(shard_idx) == INVALID_BTHREAD_ID) {
status = false;
continue;
}
auto& controller = controllers[shard_idx];
brpc::Join(task_ids[shard_idx]);
if (controller.Failed()) {
status = false;
controllers[shard_idx].Reset();
}
}
return status;
}
```
多线程发起RPC,在server有下线时会卡死在brpc::Join阶段,单线程时没有问题
堆栈:
```C++
#3 bthread_id_join ()
#2 butex_wait (void*, int, timespec const*, bool)
#1 wait_pthread (bthread::ButexPthreadWaiter&, timespec const*)
#0 syscall ()
```
**To Reproduce**
**Expected behavior**
**Versions**
OS:
Compiler:
brpc:
protobuf:
**Additional context/screenshots**
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]