From f8cca624d4c201f4317a2fa021ac71e518730644 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 15 Mar 2016 20:07:11 +0800 Subject: [PATCH] mon: ignore msg without session attached there is chance that a connection gets reset, and the session attached to a message that was sent over this connection is reset. i.e. con->set_priv(NULL) in Monitor::ms_handle_reset(), but we are about to handle_command() this message after the message is somehow requeued. so, not all MonOpRequests have an attached Session, especially those are re-dispatched. we could check conn->is_connected() everywhere, but that's error-prone and hard to maintain. so, in this change: * we need to check for the session before looking at it closer. * hold a reference to it when holding it, because in another thread, ms_handle_reset() could be freeing it. Fixes: #15113 Signed-off-by: Kefu Chai --- src/mon/Monitor.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index ceea9f1ce1b70..84e015fc53df1 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -18,6 +18,7 @@ #include #include #include +#include #include "Monitor.h" #include "common/version.h" @@ -2597,8 +2598,15 @@ void Monitor::handle_command(MonOpRequestRef op) return; } - MonSession *session = m->get_session(); - assert(session); + MonSession *session = static_cast( + m->get_connection()->get_priv()); + if (!session) { + dout(5) << __func__ << " dropping stray message " << *m << dendl; + return; + } + BOOST_SCOPE_EXIT_ALL(=) { + session->put(); + }; if (m->cmd.empty()) { string rs = "No command supplied"; -- 2.39.5