From 062baa6e1665881ee2d265919e96b54d13813689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Arnaud=20Cogolu=C3=A8gnes?= Date: Fri, 10 Jan 2025 11:36:32 +0100 Subject: [PATCH] Ignore CLI info calls during stream connection initialization The connection cannot return some information while initializing, so we just return no information. The CLI info call was supported only in the open gen_statem callback, so such a call during the connection init would make it crash. This can happen when several stream connections get closed and the user calls list_stream_consumers or list_stream_connections while the connection are recovering. This commit adds a clause for CLI info calls in the all the gen_statem callbacks and returns actual information only when appropriate. --- .../src/rabbit_stream_reader.erl | 41 +++++++++++++++---- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/deps/rabbitmq_stream/src/rabbit_stream_reader.erl b/deps/rabbitmq_stream/src/rabbit_stream_reader.erl index 51a3673d4057..1c5497d217a5 100644 --- a/deps/rabbitmq_stream/src/rabbit_stream_reader.erl +++ b/deps/rabbitmq_stream/src/rabbit_stream_reader.erl @@ -249,7 +249,10 @@ tcp_connected(info, Msg, StateData) -> ?FUNCTION_NAME, NextConnectionStep) end - end). + end); +tcp_connected({call, From}, {info, _Items}, _StateData) -> + %% must be a CLI call, not ready for this + {keep_state_and_data, {reply, From, []}}. peer_properties_exchanged(enter, _OldState, #statem_data{config = @@ -282,7 +285,10 @@ peer_properties_exchanged(info, Msg, StateData) -> ?FUNCTION_NAME, NextConnectionStep) end - end). + end); +peer_properties_exchanged({call, From}, {info, _Items}, _StateData) -> + %% must be a CLI call, not ready for this + {keep_state_and_data, {reply, From, []}}. authenticating(enter, _OldState, #statem_data{config = @@ -323,7 +329,10 @@ authenticating(info, Msg, StateData) -> ?FUNCTION_NAME, NextConnectionStep) end - end). + end); +authenticating({call, From}, {info, _Items}, _StateData) -> + %% must be a CLI call, not ready for this + {keep_state_and_data, {reply, From, []}}. tuning(enter, _OldState, #statem_data{config = @@ -360,7 +369,10 @@ tuning(info, Msg, StateData) -> ?FUNCTION_NAME, NextConnectionStep) end - end). + end); +tuning({call, From}, {info, _Items}, _StateData) -> + %% must be a CLI call, not ready for this + {keep_state_and_data, {reply, From, []}}. tuned(enter, _OldState, #statem_data{config = @@ -390,7 +402,10 @@ tuned(info, Msg, StateData) -> ?FUNCTION_NAME, NextConnectionStep) end - end). + end); +tuned({call, From}, {info, _Items}, _StateData) -> + %% must be a CLI call, not ready for this + {keep_state_and_data, {reply, From, []}}. state_timeout(State, Transport, Socket) -> rabbit_log_connection:warning("Closing connection because of timeout in state " @@ -1185,7 +1200,11 @@ close_sent(info, {resource_alarm, IsThereAlarm}, close_sent(info, Msg, _StatemData) -> rabbit_log_connection:warning("Ignored unknown message ~tp in state ~ts", [Msg, ?FUNCTION_NAME]), - keep_state_and_data. + keep_state_and_data; +close_sent({call, From}, {info, _Items}, _StateData) -> + %% must be a CLI call, returning no information + {keep_state_and_data, {reply, From, []}}. + handle_inbound_data_pre_auth(Transport, Connection, State, Data) -> handle_inbound_data(Transport, @@ -3761,8 +3780,14 @@ ensure_stats_timer(Connection = #stream_connection{}) -> rabbit_event:ensure_stats_timer(Connection, #stream_connection.stats_timer, emit_stats). -in_vhost(_Pid, undefined) -> - true; +in_vhost(Pid, undefined) -> + %% no vhost filter, but check the connection is in open state and can return information + case info(Pid, [vhost]) of + [{vhost, _}] -> + true; + _ -> + false + end; in_vhost(Pid, VHost) -> case info(Pid, [vhost]) of [{vhost, VHost}] ->