Skip to content

Fix bugs in as_awaitable, let_error and sync_wait#253

Merged
dietmarkuehl merged 2 commits intobemanproject:mainfrom
Cra3z:main
Apr 12, 2026
Merged

Fix bugs in as_awaitable, let_error and sync_wait#253
dietmarkuehl merged 2 commits intobemanproject:mainfrom
Cra3z:main

Conversation

@Cra3z
Copy link
Copy Markdown
Collaborator

@Cra3z Cra3z commented Apr 12, 2026

template <typename Receiver, typename... Args>
static auto
let_bind(auto& state, Receiver& receiver, Args&&... args) noexcept(noexcept(::beman::execution::connect(
::std::apply(::std::move(state.fun),
::std::move(state.args.template emplace<::beman::execution::detail::decayed_tuple<Args...>>(
::std::forward<Args>(args)...))),

The following code fails to compile due to an issue in the current let algorithm implementation. Since std::variant::emplace is never noexcept, noexcept(let_bind(...)) always resolves to false. This imposes a requirement that the let sender's receiver must support an error channel (set_error), causing the compilation failure for the code below.

ex::simple_counting_scope scope;
ex::spawn(
    ex::just_error(0) | ex::let_error([](int) noexcept { return ex::just(); }),
    scope.get_token()
);

@coveralls
Copy link
Copy Markdown

coveralls commented Apr 12, 2026

Coverage Status

coverage: 95.084% (-0.004%) from 95.088% — Cra3z:main into bemanproject:main

@Cra3z
Copy link
Copy Markdown
Collaborator Author

Cra3z commented Apr 12, 2026

I've noticed a data-race in run_loop/sync_wait and fixed it in 79368fe, here is the minimal repro:

ex::run_loop loop;
std::jthread worker{[&loop] {
    loop.run();
}};
auto _ = ex::sync_wait(ex::just() | ex::continues_on(loop.get_scheduler())).value();
loop.finish();

auto finish() -> void {
{
::std::lock_guard guard(this->mutex);
this->current_state = state::finishing;
}
this->condition.notify_one();
}

Can't unlock before notify_one, otherwise it will trigger the similar scenario as demonstrated in https://gcc.godbolt.org/z/zanf1avxa

@Cra3z Cra3z changed the title Fix bugs in as_awaitable and let_error Fix bugs in as_awaitable, let_error and sync_wait Apr 12, 2026
@dietmarkuehl dietmarkuehl merged commit b085c44 into bemanproject:main Apr 12, 2026
38 checks passed
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