From b56abeec121bb3a4c1f232e76794545064bb39a9 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Wed, 24 Jul 2024 11:24:26 -0400 Subject: [PATCH] Use `rabbit_misc:rs/1` on exchange resource records 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. --- deps/rabbit/src/rabbit_amqp_management.erl | 10 ++--- deps/rabbit/src/rabbit_channel.erl | 6 +-- deps/rabbit/src/rabbit_logger_exchange_h.erl | 39 ++++++++------------ 3 files changed, 24 insertions(+), 31 deletions(-) diff --git a/deps/rabbit/src/rabbit_amqp_management.erl b/deps/rabbit/src/rabbit_amqp_management.erl index 6544440dfd86..7facfe67cf71 100644 --- a/deps/rabbit/src/rabbit_amqp_management.erl +++ b/deps/rabbit/src/rabbit_amqp_management.erl @@ -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( @@ -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">>, diff --git a/deps/rabbit/src/rabbit_channel.erl b/deps/rabbit/src/rabbit_channel.erl index 1b252205472c..908892781574 100644 --- a/deps/rabbit/src/rabbit_channel.erl +++ b/deps/rabbit/src/rabbit_channel.erl @@ -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, diff --git a/deps/rabbit/src/rabbit_logger_exchange_h.erl b/deps/rabbit/src/rabbit_logger_exchange_h.erl index df65e378f0c9..781e4ce6203a 100644 --- a/deps/rabbit/src/rabbit_logger_exchange_h.erl +++ b/deps/rabbit/src/rabbit_logger_exchange_h.erl @@ -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 @@ -168,37 +166,32 @@ 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 @@ -206,12 +199,12 @@ unconfigure_exchange( 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}).