Skip to content

Commit 37140e8

Browse files
authored
Merge pull request ceph#65615 from chungfengz-syno/fix-get_addr_from_invalid_rank
mon/Elector.cc: prevent assertion failure when receiving pings from r… Reviewed-by: Radoslaw Zarzynski <[email protected]>
2 parents 1879999 + c29d6ff commit 37140e8

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/mon/Elector.cc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,10 @@ void Elector::handle_nak(MonOpRequestRef op)
454454
void Elector::begin_peer_ping(int peer)
455455
{
456456
dout(20) << __func__ << " with " << peer << dendl;
457+
if (peer < 0) {
458+
dout(20) << __func__ << " ignoring negative peer " << peer << dendl;
459+
return;
460+
}
457461
if (live_pinging.count(peer)) {
458462
// This peer is already being pinged
459463
// so we don't need to schedule another ping_check
@@ -497,7 +501,7 @@ void Elector::begin_peer_ping(int peer)
497501
bool Elector::send_peer_ping(int peer, const utime_t *n)
498502
{
499503
dout(10) << __func__ << " to peer " << peer << dendl;
500-
if (peer >= ssize(mon->monmap->ranks)) {
504+
if (peer < 0 || peer >= ssize(mon->monmap->ranks)) {
501505
// Monitor no longer exists in the monmap,
502506
// therefore, we shouldn't ping this monitor
503507
// since we cannot lookup the address!
@@ -616,6 +620,11 @@ void Elector::handle_ping(MonOpRequestRef op)
616620
MMonPing *m = static_cast<MMonPing*>(op->get_req());
617621
int prank = mon->monmap->get_rank(m->get_source_addr());
618622
dout(20) << __func__ << " from: " << prank << dendl;
623+
if (prank < 0) {
624+
dout(5) << __func__ << " from unknown addr " << m->get_source_addr()
625+
<< " mapped to rank " << prank << " (likely removed monitor) - dropping message" << dendl;
626+
return;
627+
}
619628
begin_peer_ping(prank);
620629
assimilate_connection_reports(m->tracker_bl);
621630
switch(m->op) {

0 commit comments

Comments
 (0)