From 6b6fa62cbcbd95f5cfd95ce3a705efeea7d072d3 Mon Sep 17 00:00:00 2001 From: Brandon Allard Date: Wed, 4 Oct 2023 18:04:48 -0400 Subject: [PATCH] rpc/connection_cache: always acquire mutex before accessing shared state Co-authored-by: Stephan Dollberg --- src/v/rpc/connection_cache.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/v/rpc/connection_cache.cc b/src/v/rpc/connection_cache.cc index 9887b611343d9..8f7653581a854 100644 --- a/src/v/rpc/connection_cache.cc +++ b/src/v/rpc/connection_cache.cc @@ -196,8 +196,6 @@ ss::future<> connection_cache::stop() { ss::future<> connection_cache::apply_changes( connection_allocation_strategy::changes changes, std::optional config) { - auto units = co_await _coordinator_state->mtx.get_units(); - // Add connections we have the config for. if (config) { for (auto& con_add : changes.add_connections) { @@ -250,7 +248,9 @@ ss::future<> connection_cache::remove_broker_client_coordinator( } auto holder = _gate.hold(); + auto units = co_await _coordinator_state->mtx.get_units(); auto& alloc_strat = _coordinator_state->alloc_strat; + if (alloc_strat.has_connection_assignments_for(dest)) { auto changes = alloc_strat.remove_connection_assignments_for(dest); co_await apply_changes(changes, std::nullopt); @@ -279,6 +279,7 @@ connection_cache::update_broker_client_coordinator(connection_config cfg) { } auto holder = _gate.hold(); + auto units = co_await _coordinator_state->mtx.get_units(); auto& alloc_strat = _coordinator_state->alloc_strat; if (!alloc_strat.has_connection_assignments_for(cfg.dest_node)) {