From f763d496035d2e1276bb0547cd65af37f0732c7d Mon Sep 17 00:00:00 2001 From: Yingxin Cheng Date: Fri, 5 Jul 2019 18:34:05 +0800 Subject: [PATCH] crimson/net: check front_msg correctly during sweep In order to check whether the front_msg is unchanged, we need to make sure: * The sent message is not reused; * The message to be checked is not freed; Signed-off-by: Yingxin Cheng --- src/crimson/net/Protocol.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/crimson/net/Protocol.cc b/src/crimson/net/Protocol.cc index 3ef6cc9612f49..31ec925f812f2 100644 --- a/src/crimson/net/Protocol.cc +++ b/src/crimson/net/Protocol.cc @@ -101,19 +101,19 @@ seastar::future Protocol::do_write_dispatch_sweep() size_t num_msgs = conn.out_q.size(); // we must have something to write... ceph_assert(num_msgs || need_keepalive || keepalive_ack.has_value()); - Message* msg_ptr = nullptr; + MessageRef front_msg; if (likely(num_msgs)) { - msg_ptr = conn.out_q.front().get(); + front_msg = conn.out_q.front(); } // sweep all pending writes with the concrete Protocol return socket->write(do_sweep_messages( conn.out_q, num_msgs, need_keepalive, keepalive_ack)) - .then([this, msg_ptr, num_msgs, prv_keepalive_ack=keepalive_ack] { + .then([this, front_msg, num_msgs, prv_keepalive_ack=keepalive_ack] { need_keepalive = false; if (keepalive_ack == prv_keepalive_ack) { keepalive_ack = std::nullopt; } - if (likely(num_msgs && msg_ptr == conn.out_q.front().get())) { + if (likely(num_msgs && front_msg == conn.out_q.front())) { // we have sent some messages successfully // and the out_q was not reset during socket write conn.out_q.erase(conn.out_q.begin(), conn.out_q.begin()+num_msgs); -- 2.39.5