Skip to content

Commit

Permalink
rpc/connection_cache: always acquire mutex before accessing shared state
Browse files Browse the repository at this point in the history
Co-authored-by: Stephan Dollberg <stephan@redpanda.com>
  • Loading branch information
ballard26 and StephanDollberg committed Oct 11, 2023
1 parent 71a1fb0 commit 145b166
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/v/rpc/connection_cache.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,6 @@ ss::future<> connection_cache::stop() {
ss::future<> connection_cache::apply_changes(
connection_allocation_strategy::changes changes,
std::optional<connection_config> 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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit 145b166

Please sign in to comment.