Skip to content

Commit ae5e682

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)
1 parent 402dda1 commit ae5e682

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
@@ -777,8 +777,7 @@ close(#stream_client{readers = Readers}) ->
777777

778778
update(Q, State)
779779
when ?is_amqqueue(Q) ->
780-
Pid = amqqueue:get_pid(Q),
781-
update_leader_pid(Pid, State).
780+
State.
782781

783782
update_leader_pid(Pid, #stream_client{leader = Pid} = State) ->
784783
State;

0 commit comments

Comments
 (0)