From e8b7aaa0d4de2dd8fae662b487bfb914b5ed4537 Mon Sep 17 00:00:00 2001 From: Gleb Natapov Date: Thu, 20 Feb 2025 14:16:36 +0200 Subject: [PATCH] gossiper: do not allow to assassinate non existing endpoint We assume that all endpoint states have HOST_ID set or the host id is available locally, but the assassinate code injects a state without HOST_ID for not existing endpoint violating this assumption. --- gms/gossiper.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/gms/gossiper.cc b/gms/gossiper.cc index 5ebe330a10..ac1c95ea13 100644 --- a/gms/gossiper.cc +++ b/gms/gossiper.cc @@ -1372,10 +1372,14 @@ future<> gossiper::assassinate_endpoint(sstring address) { auto now = gossiper.now(); generation_type gen(std::chrono::duration_cast((now + std::chrono::seconds(60)).time_since_epoch()).count()); version_type ver(9999); - endpoint_state ep_state = es ? *es : endpoint_state(heart_beat_state(gen, ver)); + if (!es) { + logger.warn("There is no endpoint {} to assassinate", endpoint); + throw std::runtime_error(format("There is no endpoint {} to assassinate", endpoint)); + } + endpoint_state ep_state = *es; std::vector tokens; logger.warn("Assassinating {} via gossip", endpoint); - if (es) { + const auto host_id = gossiper.get_host_id(endpoint); tokens = gossiper.get_token_metadata_ptr()->get_tokens(host_id); if (tokens.empty()) { @@ -1403,7 +1407,6 @@ future<> gossiper::assassinate_endpoint(sstring address) { } ep_state.update_timestamp(); // make sure we don't evict it too soon ep_state.get_heart_beat_state().force_newer_generation_unsafe(); - } // do not pass go, do not collect 200 dollars, just gtfo std::unordered_set tokens_set(tokens.begin(), tokens.end());