facebook / facebook/folly

Is CPUThreadPoolExecutor not alive after using several times?

Open
#958 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
30.5k
Forks
5.9k
PR merge metrics
No merged PRs in 30d

Description

I face a weird situation however I am not sure if it is really an issue?
I use CPUThreadPoolExecutor to execute my Future. After I put several tasks into the queue, those tasks was really done by cpu_executor. When I try to enqueue another series of jobs, it keep throwing error says `DefaultKeepAliveExecutor.h:130] Check failed: keepAliveCount > 0`.

Here is the complete error message.
```
F1105 22:19:28.912427 26359 DefaultKeepAliveExecutor.h:130] Check failed: keepAliveCount > 0
*** Check failure stack trace: ***
Aborted (core dumped)

And the error shows in GDB
#7 0x00005555555bb7f6 in folly::DefaultKeepAliveExecutor::keepAliveAcquire (this=0x555555b25380) at /root/folly/folly/DefaultKeepAliveExecutor.h:130
#8 0x00005555555f0911 in folly::Executor::getKeepAliveToken (executor=0x555555b25380) at /root/folly/folly/Executor.h:146
#9 0x00005555555f124e in folly::getKeepAliveToken (executor=0x555555b25380) at /root/folly/folly/Executor.h:204
#10 0x00005555555e8485 in folly::Future::via(folly::Executor*, signed char) && (this=0x7fffffffe598, executor=0x555555b25380, priority=0 '\000')
at /root/folly/folly/futures/Future-inl.h:1026
```

First I thought it is the error mentioned [here](https://github.com/facebook/folly/blob/master/folly/executors/CPUThreadPoolExecutor.h#L34). I thought maybe the queue is full. I switch the queue to [unbounded blocked queue](https://github.com/facebook/folly/blob/master/folly/executors/task_queue/UnboundedBlockingQueue.h). The same error still be thrown.
I pretty sure that the problem is not my task functions. Since even I only sleep few seconds in the tasks, it still throws out the same error.

Second, I construct another CPUThreadPoolExecutor and use it on the tasks which was not executed successfully. After I switch to the new cpu executor, there is no more error. this is also the main reason why I consider it is an issue. Following is my rough pipeline.

```c++=
folly::Future previousTask(int arg) {
// do some stuff here, without any error.
return true;
}
folly::Future errorTask(int arg) {
// What in this task is probably 80% same as previous task.
// But just as I mentioned above, even I return immediately the
// error is still thrown
return true
}

int main() {
folly::CPUThreadPoolExecutor cpu_executor(32);
for (int i = 0; i < 10000; i++)
folly::via(&cpu_executor, std::bind(previousTask, i));
for (int i = 0; i < 10000; i++) // the error happens here
folly::via(&cpu_executor, std::bind(errorTask, i));
return 0;
}
```

I also wonder that if the Future is used with `folly::via` to combine with specific executor.
Let me know if the information I provide is not enough to trace the cause. I will try leave some more useful information.

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.