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 <kchai@redhat.com>
#include <signal.h>
#include <limits.h>
#include <cstring>
+#include <boost/scope_exit.hpp>
#include "Monitor.h"
#include "common/version.h"
return;
}
- MonSession *session = m->get_session();
- assert(session);
+ MonSession *session = static_cast<MonSession *>(
+ 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";