msg/async/ProtocolV2: only update socket_addr if we learned our addr

Signed-off-by: Sage Weil <sage@redhat.com>
This commit is contained in:
Sage Weil 2018-10-29 17:23:05 -05:00
parent 5709fb9122
commit 16a0bbb0aa
3 changed files with 10 additions and 7 deletions

View File

@ -808,7 +808,7 @@ int AsyncMessenger::get_proto_version(int peer_type, bool connect) const
return 0;
}
void AsyncMessenger::learned_addr(const entity_addr_t &peer_addr_for_me)
bool AsyncMessenger::learned_addr(const entity_addr_t &peer_addr_for_me)
{
// be careful here: multiple threads may block here, and readers of
// my_addr do NOT hold any lock.
@ -817,8 +817,8 @@ void AsyncMessenger::learned_addr(const entity_addr_t &peer_addr_for_me)
// mutex. if it is already false, we need not retake the mutex at
// all.
if (!need_addr)
return ;
lock.Lock();
return false;
std::lock_guard l(lock);
if (need_addr) {
need_addr = false;
if (my_addrs->empty()) {
@ -844,8 +844,9 @@ void AsyncMessenger::learned_addr(const entity_addr_t &peer_addr_for_me)
ldout(cct, 1) << __func__ << " learned my addr " << *my_addrs
<< " (peer_addr_for_me " << peer_addr_for_me << ")" << dendl;
_init_local_connection();
return true;
}
lock.Unlock();
return false;
}
int AsyncMessenger::reap_dead()

View File

@ -372,7 +372,7 @@ public:
return 0;
}
void learned_addr(const entity_addr_t &peer_addr_for_me);
bool learned_addr(const entity_addr_t &peer_addr_for_me);
void add_accept(Worker *w, ConnectedSocket cli_socket,
const entity_addr_t &listen_addr,
const entity_addr_t &peer_addr);

View File

@ -1383,12 +1383,11 @@ CtPtr ProtocolV2::handle_server_addrvec_and_identify(char *buffer, int r) {
}
connection->set_peer_addrs(paddrs);
connection->socket_addr = peer_addr_for_me;
ldout(cct, 20) << __func__ << " connect peer addr for me is "
<< peer_addr_for_me << dendl;
connection->lock.unlock();
messenger->learned_addr(peer_addr_for_me);
bool learned = messenger->learned_addr(peer_addr_for_me);
if (cct->_conf->ms_inject_internal_delays &&
cct->_conf->ms_inject_socket_failures) {
if (rand() % cct->_conf->ms_inject_socket_failures == 0) {
@ -1401,6 +1400,9 @@ CtPtr ProtocolV2::handle_server_addrvec_and_identify(char *buffer, int r) {
}
connection->lock.lock();
if (learned) {
connection->socket_addr = peer_addr_for_me;
}
if (state != CONNECTING_WAIT_BANNER_AND_IDENTIFY) {
ldout(cct, 1) << __func__
<< " state changed while learned_addr, mark_down or "