Skip to content

Commit 415dc81

Browse files
authored
Ignore CLI info calls during stream connection initialization (#13049)
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.
1 parent a4634d3 commit 415dc81

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

deps/rabbitmq_stream/src/rabbit_stream_reader.erl

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,10 @@ tcp_connected(info, Msg, StateData) ->
249249
?FUNCTION_NAME,
250250
NextConnectionStep)
251251
end
252-
end).
252+
end);
253+
tcp_connected({call, From}, {info, _Items}, _StateData) ->
254+
%% must be a CLI call, not ready for this
255+
{keep_state_and_data, {reply, From, []}}.
253256

254257
peer_properties_exchanged(enter, _OldState,
255258
#statem_data{config =
@@ -282,7 +285,10 @@ peer_properties_exchanged(info, Msg, StateData) ->
282285
?FUNCTION_NAME,
283286
NextConnectionStep)
284287
end
285-
end).
288+
end);
289+
peer_properties_exchanged({call, From}, {info, _Items}, _StateData) ->
290+
%% must be a CLI call, not ready for this
291+
{keep_state_and_data, {reply, From, []}}.
286292

287293
authenticating(enter, _OldState,
288294
#statem_data{config =
@@ -323,7 +329,10 @@ authenticating(info, Msg, StateData) ->
323329
?FUNCTION_NAME,
324330
NextConnectionStep)
325331
end
326-
end).
332+
end);
333+
authenticating({call, From}, {info, _Items}, _StateData) ->
334+
%% must be a CLI call, not ready for this
335+
{keep_state_and_data, {reply, From, []}}.
327336

328337
tuning(enter, _OldState,
329338
#statem_data{config =
@@ -360,7 +369,10 @@ tuning(info, Msg, StateData) ->
360369
?FUNCTION_NAME,
361370
NextConnectionStep)
362371
end
363-
end).
372+
end);
373+
tuning({call, From}, {info, _Items}, _StateData) ->
374+
%% must be a CLI call, not ready for this
375+
{keep_state_and_data, {reply, From, []}}.
364376

365377
tuned(enter, _OldState,
366378
#statem_data{config =
@@ -390,7 +402,10 @@ tuned(info, Msg, StateData) ->
390402
?FUNCTION_NAME,
391403
NextConnectionStep)
392404
end
393-
end).
405+
end);
406+
tuned({call, From}, {info, _Items}, _StateData) ->
407+
%% must be a CLI call, not ready for this
408+
{keep_state_and_data, {reply, From, []}}.
394409

395410
state_timeout(State, Transport, Socket) ->
396411
rabbit_log_connection:warning("Closing connection because of timeout in state "
@@ -1185,7 +1200,11 @@ close_sent(info, {resource_alarm, IsThereAlarm},
11851200
close_sent(info, Msg, _StatemData) ->
11861201
rabbit_log_connection:warning("Ignored unknown message ~tp in state ~ts",
11871202
[Msg, ?FUNCTION_NAME]),
1188-
keep_state_and_data.
1203+
keep_state_and_data;
1204+
close_sent({call, From}, {info, _Items}, _StateData) ->
1205+
%% must be a CLI call, returning no information
1206+
{keep_state_and_data, {reply, From, []}}.
1207+
11891208

11901209
handle_inbound_data_pre_auth(Transport, Connection, State, Data) ->
11911210
handle_inbound_data(Transport,
@@ -3761,8 +3780,14 @@ ensure_stats_timer(Connection = #stream_connection{}) ->
37613780
rabbit_event:ensure_stats_timer(Connection,
37623781
#stream_connection.stats_timer, emit_stats).
37633782

3764-
in_vhost(_Pid, undefined) ->
3765-
true;
3783+
in_vhost(Pid, undefined) ->
3784+
%% no vhost filter, but check the connection is in open state and can return information
3785+
case info(Pid, [vhost]) of
3786+
[{vhost, _}] ->
3787+
true;
3788+
_ ->
3789+
false
3790+
end;
37663791
in_vhost(Pid, VHost) ->
37673792
case info(Pid, [vhost]) of
37683793
[{vhost, VHost}] ->

0 commit comments

Comments
 (0)