diff --git a/table_helper.cc b/table_helper.cc index b96e97c977..5fb1b5788f 100644 --- a/table_helper.cc +++ b/table_helper.cc @@ -152,9 +152,13 @@ future<> table_helper::insert(cql3::query_processor& qp, service::migration_mana break; } } + // Pin a strong ref locally: while we suspend in execute(), a concurrent + // insert() on this shard may reset _insert_stmt to nullptr if the + // prepared_statements_cache entry gets invalidated, freeing the object. + auto stmt = _insert_stmt; auto opts = opt_maker(); opts.prepare(_prepared_stmt->bound_names); - co_await _insert_stmt->execute(qp, qs, opts, std::nullopt); + co_await stmt->execute(qp, qs, opts, std::nullopt); } future<> table_helper::setup_keyspace(cql3::query_processor& qp, service::migration_manager& mm, std::string_view keyspace_name, sstring replication_strategy_name,