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)) {