From 208dc558a9b2b4f4952d71cbf94ec7489517d41c Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 8 Oct 2009 11:45:27 -0700 Subject: [PATCH] mon: fix session close races Make sure we don't use a connection's session if it is closed. Remove session from connection on reset. --- src/mon/Monitor.cc | 7 +++++++ src/mon/Session.h | 1 + 2 files changed, 8 insertions(+) diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index d2ca9abb8987b..b736c761e9699 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -473,6 +473,10 @@ void Monitor::handle_subscribe(MMonSubscribe *m) bool reply = false; Session *s = (Session *)m->get_connection()->get_priv(); + if (s && s->closed) { + s->put(); + s = NULL; + } if (!s) { s = session_map.new_session(m->get_source_inst()); m->get_connection()->set_priv(s->get()); @@ -520,6 +524,9 @@ bool Monitor::ms_handle_reset(Connection *con, const entity_addr_t& peer) dout(10) << "reset/close on session " << s->inst << dendl; session_map.remove_session(s); s->put(); + + // remove from connection, too. + con->set_priv(NULL); return true; } diff --git a/src/mon/Session.h b/src/mon/Session.h index 60e2834a442ff..a42d7b37561a8 100644 --- a/src/mon/Session.h +++ b/src/mon/Session.h @@ -58,6 +58,7 @@ struct SessionMap { s->sub_map.clear(); s->item.remove_myself(); s->put(); + s->closed = true; } Session *new_session(entity_inst_t i) { -- 2.39.5