Skip to content

Commit dcb8a92

Browse files
committed
demo::task supports async cancellation
with poll_context: when stop_source.request_stop() calls poll_context::cancel(), the target operation's io_base::cancel() is called inline. this calls sender_awaiter::stop() which transitions from stop_state::stopping to stopped. because request_stop() returns back to callback_t in stop_state::stopped, complete_stopped() is called there with uring_context: uring_context::cancel() is asynchronous, so callback_t is still in stop_state::stopping when request_stop() returns. run_one() eventually sees the target operation complete with ECANCELED and calls io_base::cancel(). when that calls sender_awaiter::stop(), the state is still stop_state::stopping, so complete_stopped() never gets called this causes beman.net.examples.client to exit before demo::scope gets the stop signal from the 2 coroutines: > ERROR: scope destroyed with live jobs: 2 to address this, callback_t now handles this async case by transitioning back to stop_state::running after stop_source.request_stop() returns Signed-off-by: Casey Bodley <cbodley@redhat.com>
1 parent c87fea3 commit dcb8a92

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

examples/demo_task.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,12 @@ struct task {
184184
state->callback.reset();
185185
state->handle->stop_state = task::stop_state::stopping;
186186
state->handle->stop_source.request_stop();
187-
if (state->handle->stop_state == task::stop_state::stopped)
187+
if (state->handle->stop_state == task::stop_state::stopped) {
188188
this->object->handle->state->complete_stopped();
189+
} else {
190+
// transition back to running so sender_awaiter::stop() can safely complete later
191+
state->handle->stop_state = task::stop_state::running;
192+
}
189193
}
190194
};
191195
using stop_token = decltype(ex::get_stop_token(ex::get_env(::std::declval<Receiver>())));

0 commit comments

Comments
 (0)