From b5674a5b3eeacfef89522b26e2021fa26b08c0e6 Mon Sep 17 00:00:00 2001 From: Pablo Marcos Date: Wed, 18 Mar 2026 12:37:17 +0000 Subject: [PATCH] Fix segfault It happened when upgrading 25.10 to 25.12: https://github.com/ClickHouse/clickhouse-core-incidents/issues/1479 --- src/handle_commit.cxx | 3 ++- src/handle_snapshot_sync.cxx | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/handle_commit.cxx b/src/handle_commit.cxx index 3a8c9177..c12224c8 100644 --- a/src/handle_commit.cxx +++ b/src/handle_commit.cxx @@ -722,7 +722,8 @@ void raft_server::on_snapshot_completed ptr new_snp = state_machine_->last_snapshot(); set_last_snapshot(new_snp); ptr params = ctx_->get_params(); - if ( new_snp->get_last_log_idx() > + if ( new_snp && + new_snp->get_last_log_idx() > (ulong)params->reserved_log_items_ ) { ulong compact_upto = new_snp->get_last_log_idx() - (ulong)params->reserved_log_items_; diff --git a/src/handle_snapshot_sync.cxx b/src/handle_snapshot_sync.cxx index 4f1adefc..0cca3c67 100644 --- a/src/handle_snapshot_sync.cxx +++ b/src/handle_snapshot_sync.cxx @@ -117,9 +117,9 @@ ptr raft_server::create_sync_snapshot_req(ptr& pp, // LCOV_EXCL_START p_er( "system is running into fatal errors, failed to find a " "snapshot for peer %d (snapshot null: %d, snapshot " - "doesn't contais lastLogIndex: %d)", + "doesn't contain lastLogIndex: %d)", p.get_id(), snp == nilptr ? 1 : 0, - last_log_idx > snp->get_last_log_idx() ? 1 : 0 ); + (snp != nilptr && last_log_idx > snp->get_last_log_idx()) ? 1 : 0 ); if (snp) { p_er("last log idx %" PRIu64 ", snp last log idx %" PRIu64, last_log_idx, snp->get_last_log_idx());