From a97706160277b8430dc22b1a951b55e420221886 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 3 Mar 2021 11:39:36 +0800 Subject: [PATCH] crimson/mon: keep a copy of sent MMonCommand messages as per Yingxin Cheng, > The send process can be asynchronous (there is a conn.out_q, or if the > underlying socket lives in a different core in the m:n model to be > ordered there). If user really wants to reuse a message, they must be > careful not to modify it because it may result in modifing the pending > messages. > > I think the best way is to copy the message if user want to resend it, > and keep the ceph_assert(!msg->get_seq()). It may looks good to reuse a > message under lossy policy, but the correctness is now up to user not to > modify it inplace. see also https://github.com/ceph/ceph/pull/39786 Signed-off-by: Kefu Chai --- src/crimson/mon/MonClient.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/crimson/mon/MonClient.cc b/src/crimson/mon/MonClient.cc index 7baa3b34f1fc7..5b68ab8da7de8 100644 --- a/src/crimson/mon/MonClient.cc +++ b/src/crimson/mon/MonClient.cc @@ -1010,9 +1010,8 @@ Client::run_command(std::string&& cmd, m->set_tid(tid); m->cmd = {std::move(cmd)}; m->set_data(std::move(bl)); - mon_commands.emplace_back(m); - auto& command = mon_commands.back(); - return send_message(command.req).then([&result=command.result] { + auto& command = mon_commands.emplace_back(make_message(*m)); + return send_message(std::move(m)).then([&result=command.result] { return result.get_future(); }); } @@ -1042,7 +1041,7 @@ seastar::future<> Client::on_session_opened() }).then([this] { return seastar::parallel_for_each(mon_commands, [this](auto &command) { - return send_message(command.req); + return send_message(make_message(*command.req)); }); }); } -- 2.39.5