Avoid async scope lockup
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start from the provided async_scope, test2, and test3 reproducer and compare the three scheduling cases while tracing cancellation and scope completion. Reproduce the destructor assertion, determine why cases 2 and 3 remain unfinished after request_stop(), and verify that the intended cancellation behavior completes without the assertion.
Written by the indexing model from the issue text.
Description
exec::task<void> test(asio::io_context &ioContext)
{
asio::steady_timer timer(ioContext);
timer.expires_after(std::chrono::seconds(10));
auto [error] = co_await timer.async_wait(asio::as_tuple(exec::asio::use_sender));
}
exec::task<void> test2(exec::async_scope& scope, asio::io_context &ioContext)
{
#if 1
co_await exec::reschedule_coroutine_on(stdexec::inline_scheduler{});
co_await scope.nest(test(ioContext));
#elif 0
co_await stdexec::on(stdexec::inline_scheduler{}, scope.nest(test(ioContext)));
#elif 0
co_await scope.nest(stdexec::on(stdexec::inline_scheduler{}, test(ioContext)));
#endif
}
exec::task<void> test3(exec::async_scope& scope, asio::io_context &ioContext)
{
co_await test2(scope, ioContext);
}
asio::io_context ioContext;
MyThread recvThread;
std::optional<exec::async_scope> asyncScope;
asyncScope.emplace();
exec::static_thread_pool ctx{1};
asio::executor_work_guard<asio::io_context::executor_type> workGuard(
asio::make_work_guard(ioContext));
recvThread.start([&]
{
ioContext.run();
printf("test\n");
}, "client_network_thread");
exec::start_detached(stdexec::starts_on(MainThreadScheduler(), test3(*asyncScope, ioContext)));
Scheduler::getSingleton()->run(GetTicks());
sleep(5);
workGuard.reset();
asyncScope->request_stop();
recvThread.join();
asyncScope.emplace();
What I am attempting to do is to wrap an async function in an async scope t make it cancellable.
In this example the MainThreadScheduler only schedules one initial time so it is expected that it will never fully finish the test3 task.
However I would still like to successfully cancel it. In the test2 function the first case works as expected. Both case 2 and 3 assert inside the asyncScope destructor since the work isn't considered finished. It wasn't fully clear to me why the work isn't considered finished in these cases. Especially in case 2.
- Dominant language
- C++
- Stars
- 2.4k
- Forks
- 270
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 37
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from NVIDIA/stdexec
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
-
Difficulty 4/5 3-5 days Newbie friendliness 66/100
-
Difficulty 3/5 1-2 days Newbie friendliness 74/100
Similar issues
-
ai_reviewed
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ydb-platform/ydb#53869 · 3 comments ·
-
bug cert blocker needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
project-chip/connectedhomeip#74373 ·
-
upstream update
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
conan-io/conan-center-index#31035 ·
-
Bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
documentation
Difficulty 1/5 Under an hour Newbie friendliness 85/100
vllm-project/vllm-ascend#17329 ·