From a1613e60a0a6a78bd9ccd09b410b47f5123d844b Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 8 Jan 2019 07:13:13 -0600 Subject: [PATCH] msg/async/Protocol*: fix mark_down vs accept race If we mark_down the connection while we have the lock dropped the state maybe CLOSED when we retake it. Bail out if that happens instead of continuing to process the connection and eventually running into an assertion on can_write. Fixes: http://tracker.ceph.com/issues/36497 Signed-off-by: Sage Weil --- src/msg/async/ProtocolV1.cc | 7 +++++++ src/msg/async/ProtocolV2.cc | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/msg/async/ProtocolV1.cc b/src/msg/async/ProtocolV1.cc index ab4b526105f1..0d71148ffbd9 100644 --- a/src/msg/async/ProtocolV1.cc +++ b/src/msg/async/ProtocolV1.cc @@ -1933,6 +1933,13 @@ CtPtr ProtocolV1::handle_connect_message_2() { need_challenge ? &authorizer_challenge : nullptr) || !authorizer_valid) { connection->lock.lock(); + if (state != ACCEPTING_WAIT_CONNECT_MSG_AUTH) { + ldout(cct, 1) << __func__ + << " state changed while accept, it must be mark_down" + << dendl; + ceph_assert(state == CLOSED); + return _fault(); + } if (need_challenge && !had_challenge && authorizer_challenge) { ldout(cct, 10) << __func__ << ": challenging authorizer" << dendl; diff --git a/src/msg/async/ProtocolV2.cc b/src/msg/async/ProtocolV2.cc index 99b424e6dbc3..526545d6ea80 100644 --- a/src/msg/async/ProtocolV2.cc +++ b/src/msg/async/ProtocolV2.cc @@ -1980,6 +1980,13 @@ CtPtr ProtocolV2::handle_connect_message_2() { need_challenge ? &authorizer_challenge : nullptr) || !authorizer_valid) { connection->lock.lock(); + if (state != ACCEPTING_WAIT_CONNECT_MSG_AUTH) { + ldout(cct, 1) << __func__ + << " state changed while accept, it must be mark_down" + << dendl; + ceph_assert(state == CLOSED); + return _fault(); + } if (need_challenge && !had_challenge && authorizer_challenge) { ldout(cct, 10) << __func__ << ": challenging authorizer" << dendl; -- 2.47.3