From 787dd1709797876dd9fa6004c6723df859003b59 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Sat, 18 Feb 2012 13:45:37 -0800 Subject: [PATCH] msgr: fix shutdown vs accept race This is a kludge. The real fix is to rewrite SimpleMessenger as a state machine. Fixes: #2073 Signed-off-by: Sage Weil --- src/msg/SimpleMessenger.cc | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/msg/SimpleMessenger.cc b/src/msg/SimpleMessenger.cc index 32eb818217b92..a6898e37e28c6 100644 --- a/src/msg/SimpleMessenger.cc +++ b/src/msg/SimpleMessenger.cc @@ -729,6 +729,8 @@ int SimpleMessenger::Pipe::accept() << dendl; msgr->lock.Lock(); + if (msgr->dispatch_queue.stop) + goto shutting_down; // note peer's type, flags set_peer_type(connect.host_type); @@ -766,6 +768,9 @@ int SimpleMessenger::Pipe::accept() goto reply; } msgr->lock.Lock(); + if (msgr->dispatch_queue.stop) + goto shutting_down; + // existing? if (msgr->rank_pipe.count(peer_addr)) { @@ -946,6 +951,8 @@ int SimpleMessenger::Pipe::accept() ldout(msgr->cct,10) << "accept features " << connection_state->get_features() << dendl; // ok! + if (msgr->dispatch_queue.stop) + goto shutting_down; register_pipe(); msgr->lock.Unlock(); @@ -985,16 +992,25 @@ int SimpleMessenger::Pipe::accept() fail_unlocked: pipe_lock.Lock(); - bool queued = is_queued(); - if (queued) - state = STATE_CONNECTING; - else - state = STATE_CLOSED; - fault(); - if (queued) - start_writer(); + { + bool queued = is_queued(); + if (queued && state != STATE_CLOSED) + state = STATE_CONNECTING; + else + state = STATE_CLOSED; + fault(); + if (queued) + start_writer(); + } pipe_lock.Unlock(); return -1; + + shutting_down: + msgr->lock.Unlock(); + state = STATE_CLOSED; + fault(); + msgr->lock.Unlock(); + return -1; } int SimpleMessenger::Pipe::connect() -- 2.39.5