Skip to content

Commit 540c028

Browse files
the-mikedavismergify[bot]
authored andcommitted
rabbit_stream_queue: Only update leader PID on stream_leader_change event
`rabbit_stream_coordinator` is the only authority on a stream queue's leader PID, so we should only trust that process for notifications of leader changes. The call to `update_leader_pid/2` from the `update/2` callback may trigger the effects of a leader change for the stream queue's state without interacting with the stream coordinator. This is noticeable on the Khepri branch where the leader failover test case flakes in cases where the channel process reads a stale record from the metadata store with an old leader PID and mistakenly triggers the leader change to the stale leader PID. Removing this block stops the flake without removing the leader change mechanism to resend unconfirmed messages: the handler of the `stream_leader_change` event from the stream coordinator still triggers leader information changes to the queue's state. This bug is also possible on main but is not reproducible in practice because mnesia updates fast enough that we are very unlikely to read a stale leader PID when looking up the queue record. (cherry picked from commit ec0ffde) (cherry picked from commit ae5e682)
1 parent 9ffb44a commit 540c028

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

deps/rabbit/src/rabbit_stream_queue.erl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -768,8 +768,7 @@ close(#stream_client{readers = Readers}) ->
768768

769769
update(Q, State)
770770
when ?is_amqqueue(Q) ->
771-
Pid = amqqueue:get_pid(Q),
772-
update_leader_pid(Pid, State).
771+
State.
773772

774773
update_leader_pid(Pid, #stream_client{leader = Pid} = State) ->
775774
State;

0 commit comments

Comments
 (0)