crimson/osd: capture watcher when calling its member function 33425/head
authorKefu Chai <kchai@redhat.com>
Thu, 20 Feb 2020 08:09:19 +0000 (16:09 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 20 Feb 2020 08:09:22 +0000 (16:09 +0800)
otherwise the extracted node handler will be destroyed, and so does the
watcher enclosed in it.

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/crimson/osd/ops_executer.cc

index c3d797e581598bbf3ee5b88eae8c163120a536f0..46c9ce3ee6d81f38941e6e0b4f49dc001e46a73c 100644 (file)
@@ -210,11 +210,13 @@ OpsExecuter::watch_errorator::future<> OpsExecuter::do_op_watch_subop_unwatch(
     },
     [] (auto&& ctx, ObjectContextRef obc) {
       if (auto nh = obc->watchers.extract(ctx.key); !nh.empty()) {
-        logger().info("op_effect: disconnect watcher {}", ctx.key);
-        return nh.mapped()->remove(ctx.send_disconnect);
+        return seastar::do_with(std::move(nh.mapped()),
+                         [ctx](auto&& watcher) {
+          logger().info("op_effect: disconnect watcher {}", ctx.key);
+          return watcher->remove(ctx.send_disconnect);
+        });
       } else {
-        logger().info("op_effect: disconnect failed to find watcher {}",
-                      ctx.key);
+        logger().info("op_effect: disconnect failed to find watcher {}", ctx.key);
         return seastar::now();
       }
     });