Skip to content

Commit e778904

Browse files
committed
fix(reactor): clear the op keepalive before publishing its continuation
coro_resume published the completion's continuation through dispatch_coro before moving impl_ptr out of the op. When the continuation targets a strand drained on another thread, that thread can resume it and reuse the op via reset() the instant it is published, racing the impl_ptr move on the completing thread. Move the keepalive out first so the write is ordered before the publish; the ref still lives in the local across resume(), so the op storage survives the continuation.
1 parent 7935c82 commit e778904

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

include/boost/corosio/native/detail/coro_op_complete.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ inline void
125125
coro_resume(coro_op* self) noexcept
126126
{
127127
self->cont.h = self->h;
128-
auto next = dispatch_coro(self->ex, self->cont);
128+
// Clear the keepalive before publishing the continuation: a strand
129+
// drained on another thread can reuse this op via reset() the instant
130+
// it runs, so this write must be ordered before the publish, not after.
129131
auto suicide = std::move(self->impl_ptr);
132+
auto next = dispatch_coro(self->ex, self->cont);
130133
next.resume();
131134
// suicide drops here; may destroy impl + self.
132135
}

0 commit comments

Comments
 (0)