Skip to content

Commit

Permalink
r/consensus: acquire lock when waiting for gate to be closed
Browse files Browse the repository at this point in the history
When raft stops the last step in stop sequence is closing gate. After
gate is closed all the background futures are guaranteed to be finished.
However it may happen that the fiber is waiting for an `_op_lock` while
gate is being closed. We need to make sure that when the `_op_lock` is
acquired the `consensus` instance is still alive.

Clearing and marking an oplock as broken after dispatching `gate`
close makes it impossible for incoming fibers to access `consensus`
after it is deleted.

Signed-off-by: Michal Maslanka <michal@redpanda.com>
  • Loading branch information
mmaslankaprv committed Aug 1, 2022
1 parent acde644 commit b7c5802
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/v/raft/consensus.cc
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,14 @@ ss::future<> consensus::stop() {
co_await _event_manager.stop();
co_await _append_requests_buffer.stop();
co_await _batcher.stop();
co_await _bg.close();

auto f = _bg.close();
/**
* acquire lock after closing the gate, this way after
*/
auto u = co_await _op_lock.get_units();
_op_lock.broken();
co_await std::move(f);

// close writer if we have to
if (unlikely(_snapshot_writer)) {
Expand Down

0 comments on commit b7c5802

Please sign in to comment.