From fed9f94300609a41d98bc63cd783df74ed115958 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Fri, 10 Jul 2020 11:24:08 -0400 Subject: [PATCH] librbd: ensure all asio completions are complete at ImageCtx destruction With multiple threads of execution possible, we need to ensure that all completions have fired prior to the destruction of the AsioEngine. We also need to ensure that the AsioEngine is destoyed outside the context of its owned stands. Signed-off-by: Jason Dillaman --- src/librbd/ImageCtx.cc | 5 +++++ src/librbd/asio/ContextWQ.cc | 1 + 2 files changed, 6 insertions(+) diff --git a/src/librbd/ImageCtx.cc b/src/librbd/ImageCtx.cc index 2c238abbde73a..ddfa8efc76894 100644 --- a/src/librbd/ImageCtx.cc +++ b/src/librbd/ImageCtx.cc @@ -172,6 +172,11 @@ librados::IoCtx duplicate_io_ctx(librados::IoCtx& io_ctx) { delete state; delete plugin_registry; + + // destroy our AsioEngine via its shared io_context to ensure that we + // aren't executing within an AsioEngine-owned strand + auto& io_context = asio_engine->get_io_context(); + boost::asio::post(io_context, [asio_engine=std::move(asio_engine)]() {}); } void ImageCtx::init() { diff --git a/src/librbd/asio/ContextWQ.cc b/src/librbd/asio/ContextWQ.cc index db4fadec69f6f..2d12d5080fd1d 100644 --- a/src/librbd/asio/ContextWQ.cc +++ b/src/librbd/asio/ContextWQ.cc @@ -22,6 +22,7 @@ ContextWQ::ContextWQ(CephContext* cct, boost::asio::io_context& io_context) ContextWQ::~ContextWQ() { ldout(m_cct, 20) << dendl; + drain(); } void ContextWQ::drain() { -- 2.39.5