Skip to content

Commit fb4f50d

Browse files
committed
Catch ETS exception when system is still starting
Because the ETS table may be not created yet. A stream connection can call another node to get the port of the stream plugin on this node. The stream plugin uses the rabbit_networking module, which relies on an ETS table to store listener information. The table may be not created yet when the node starts up, so the calling node ends up logging a large stack trace. This commit catches the exception and logs a simple message. This reduces unnecessary noise in the logs.
1 parent 5abeb75 commit fb4f50d

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

deps/rabbitmq_stream/src/rabbit_stream.erl

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,19 @@ port() ->
8787
end.
8888

8989
port_from_listener() ->
90-
Listeners = rabbit_networking:node_listeners(node()),
91-
Port =
90+
try
91+
Listeners = rabbit_networking:node_listeners(node()),
9292
lists:foldl(fun (#listener{port = Port, protocol = stream}, _Acc) ->
9393
Port;
9494
(_, Acc) ->
9595
Acc
9696
end,
97-
undefined, Listeners),
98-
Port.
97+
undefined, Listeners)
98+
catch error:Reason ->
99+
%% can happen if a remote node calls and the current has not fully started yet
100+
rabbit_log:info("Error while retrieving stream plugin port: ~tp", [Reason]),
101+
{error, Reason}
102+
end.
99103

100104
tls_port() ->
101105
case application:get_env(rabbitmq_stream, advertised_tls_port,
@@ -108,16 +112,20 @@ tls_port() ->
108112
end.
109113

110114
tls_port_from_listener() ->
111-
Listeners = rabbit_networking:node_listeners(node()),
112-
Port =
115+
try
116+
Listeners = rabbit_networking:node_listeners(node()),
113117
lists:foldl(fun (#listener{port = Port, protocol = 'stream/ssl'},
114118
_Acc) ->
115119
Port;
116120
(_, Acc) ->
117121
Acc
118122
end,
119-
undefined, Listeners),
120-
Port.
123+
undefined, Listeners)
124+
catch error:Reason ->
125+
%% can happen if a remote node calls and the current has not fully started yet
126+
rabbit_log:info("Error while retrieving stream plugin port: ~tp", [Reason]),
127+
{error, Reason}
128+
end.
121129

122130
stop(_State) ->
123131
ok.

0 commit comments

Comments
 (0)