From 1ca4dc6d1bd6aebece500c6e91f6a9871af0e1f1 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Fri, 9 Sep 2016 10:42:50 -0400 Subject: [PATCH] librbd: possible deadlock if cluster connection closed after image Fixes: http://tracker.ceph.com/issues/17254 Signed-off-by: Jason Dillaman (cherry picked from commit 818c2f2abc972f689acb7d783c2a684bcc9e6e51) --- src/librbd/ImageWatcher.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/librbd/ImageWatcher.cc b/src/librbd/ImageWatcher.cc index 7aeb1c93489c8..c828163b8adb4 100644 --- a/src/librbd/ImageWatcher.cc +++ b/src/librbd/ImageWatcher.cc @@ -54,13 +54,19 @@ struct C_UnwatchAndFlush : public Context { r = rados.aio_watch_flush(aio_comp); assert(r == 0); aio_comp->release(); - } else { - Context::complete(ret_val); + return; } + + // ensure our reference to the RadosClient is released prior + // to completing the callback to avoid racing an explicit + // librados shutdown + Context *ctx = on_finish; + delete this; + + ctx->complete(ret_val); } virtual void finish(int r) override { - on_finish->complete(r); } }; -- 2.39.5