From 13e8564238652d6407dae53808b52ad298f762ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Cogolu=C3=A8gnes?= <514737+acogoluegnes@users.noreply.github.com> Date: Mon, 16 Jun 2025 16:38:29 +0200 Subject: [PATCH] Return error if stream leader is undefined in stream manager A stream may not have a leader temporarily for several reasons, e.g. after it has been restarted. The stream manager may return undefined in this case. Some client code may crash because it expects a PID or an error, but not undefined. This commit makes sure the leader PID is an actual Erlang PID and returns {error, not_available} if it is not. References #13962 --- deps/rabbitmq_stream/src/rabbit_stream_manager.erl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/deps/rabbitmq_stream/src/rabbit_stream_manager.erl b/deps/rabbitmq_stream/src/rabbit_stream_manager.erl index 876d33d739a4..9711046f147a 100644 --- a/deps/rabbitmq_stream/src/rabbit_stream_manager.erl +++ b/deps/rabbitmq_stream/src/rabbit_stream_manager.erl @@ -203,7 +203,7 @@ lookup_leader(VirtualHost, Stream) -> {ok, LeaderPid}; false -> case leader_from_members(Q) of - {ok, Pid} -> + {ok, Pid} when is_pid(Pid) -> {ok, Pid}; _ -> {error, not_available} @@ -856,7 +856,7 @@ leader_from_members(Q) -> {error, not_found} end. -process_alive(Pid) -> +process_alive(Pid) when is_pid(Pid) -> CurrentNode = node(), case node(Pid) of nonode@nohost -> @@ -870,7 +870,9 @@ process_alive(Pid) -> _ -> false end - end. + end; +process_alive(_) -> + false. is_stream_queue(Q) -> case amqqueue:get_type(Q) of