Skip to content

Commit

Permalink
Use rabbit_misc:rs/1 on exchange resource records
Browse files Browse the repository at this point in the history
This fixes a potential crash in `rabbit_amqp_amanegment` where we tried
to format the exchange resource as a string (`~ts`). The other changes
are cosmetic.
  • Loading branch information
the-mikedavis committed Jul 24, 2024
1 parent fb3154b commit b56abee
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 31 deletions.
10 changes: 5 additions & 5 deletions deps/rabbit/src/rabbit_amqp_management.erl
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ handle_http_req(<<"PUT">>,
{error, timeout} ->
throw(
<<"503">>,
"Could not create exchange '~ts' in vhost '~ts' "
"because the operation timed out",
[XName, Vhost])
"Could not create ~ts because the operation "
"timed out",
[rabbit_misc:rs(XName)])
end
end,
try rabbit_exchange:assert_equivalence(
Expand Down Expand Up @@ -300,8 +300,8 @@ handle_http_req(<<"DELETE">>,
{error, timeout} ->
throw(
<<"503">>,
"failed to delete exchange '~ts' due to a timeout",
[XNameBin])
"failed to delete ~ts due to a timeout",
[rabbit_misc:rs(XName)])
end;

handle_http_req(<<"POST">>,
Expand Down
6 changes: 3 additions & 3 deletions deps/rabbit/src/rabbit_channel.erl
Original file line number Diff line number Diff line change
Expand Up @@ -2581,9 +2581,9 @@ handle_method(#'exchange.declare'{exchange = XNameBin,
{error, timeout} ->
rabbit_misc:protocol_error(
internal_error,
"failed to declare exchange '~ts' in vhost '~ts' "
"because the operation timed out",
[XNameBinStripped, VHostPath])
"failed to declare ~ts because the operation "
"timed out",
[rabbit_misc:rs(ExchangeName)])
end
end,
ok = rabbit_exchange:assert_equivalence(X, CheckedType, Durable,
Expand Down
39 changes: 16 additions & 23 deletions deps/rabbit/src/rabbit_logger_exchange_h.erl
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,16 @@ wait_for_initial_pass(N) ->
end.

setup_proc(
#{config := #{exchange := #resource{name = Name,
virtual_host = VHost}}} = Config) ->
#{config := #{exchange := Exchange}} = Config) ->
case declare_exchange(Config) of
ok ->
?LOG_INFO(
"Logging to exchange '~ts' in vhost '~ts' ready", [Name, VHost],
"Logging to ~ts ready", [rabbit_misc:rs(Exchange)],
#{domain => ?RMQLOG_DOMAIN_GLOBAL});
error ->
?LOG_DEBUG(
"Logging to exchange '~ts' in vhost '~ts' not ready, "
"trying again in ~b second(s)",
[Name, VHost, ?DECL_EXCHANGE_INTERVAL_SECS],
"Logging to ~ts not ready, trying again in ~b second(s)",
[rabbit_misc:rs(Exchange), ?DECL_EXCHANGE_INTERVAL_SECS],
#{domain => ?RMQLOG_DOMAIN_GLOBAL}),
receive
stop -> ok
Expand All @@ -168,50 +166,45 @@ setup_proc(
end
end.

declare_exchange(
#{config := #{exchange := #resource{name = Name,
virtual_host = VHost} = Exchange}}) ->
declare_exchange(#{config := #{exchange := Exchange}}) ->
try rabbit_exchange:declare(
Exchange, topic, true, false, true, [], ?INTERNAL_USER) of
{ok, #exchange{}} ->
?LOG_DEBUG(
"Declared exchange '~ts' in vhost '~ts'",
[Name, VHost],
"Declared ~ts",
[rabbit_misc:rs(Exchange)],
#{domain => ?RMQLOG_DOMAIN_GLOBAL}),
ok;
{error, timeout} ->
?LOG_DEBUG(
"Could not declare exchange '~ts' in vhost '~ts' because the "
"operation timed out",
[Name, VHost],
"Could not declare ~ts because the operation timed out",
[rabbit_misc:rs(Exchange)],
#{domain => ?RMQLOG_DOMAIN_GLOBAL}),
error
catch
Class:Reason ->
?LOG_DEBUG(
"Could not declare exchange '~ts' in vhost '~ts', "
"reason: ~0p:~0p",
[Name, VHost, Class, Reason],
"Could not declare ~ts, reason: ~0p:~0p",
[rabbit_misc:rs(Exchange), Class, Reason],
#{domain => ?RMQLOG_DOMAIN_GLOBAL}),
error
end.

unconfigure_exchange(
#{config := #{exchange := #resource{name = Name,
virtual_host = VHost} = Exchange,
#{config := #{exchange := Exchange,
setup_proc := Pid}}) ->
Pid ! stop,
case rabbit_exchange:ensure_deleted(Exchange, false, ?INTERNAL_USER) of
ok ->
ok;
{error, timeout} ->
?LOG_ERROR(
"Could not delete exchange '~ts' in vhost '~ts' due to a timeout",
[Name, VHost],
"Could not delete ~ts due to a timeout",
[rabbit_misc:rs(Exchange)],
#{domain => ?RMQLOG_DOMAIN_GLOBAL}),
ok
end,
?LOG_INFO(
"Logging to exchange '~ts' in vhost '~ts' disabled",
[Name, VHost],
"Logging to ~ts disabled",
[rabbit_misc:rs(Exchange)],
#{domain => ?RMQLOG_DOMAIN_GLOBAL}).

0 comments on commit b56abee

Please sign in to comment.