Skip to content

Commit 2fa64c4

Browse files
the-mikedavismergify[bot]
authored andcommitted
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. (cherry picked from commit b56abee)
1 parent c530a21 commit 2fa64c4

File tree

3 files changed

+24
-31
lines changed

3 files changed

+24
-31
lines changed

deps/rabbit/src/rabbit_amqp_management.erl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,9 @@ handle_http_req(<<"PUT">>,
218218
{error, timeout} ->
219219
throw(
220220
<<"503">>,
221-
"Could not create exchange '~ts' in vhost '~ts' "
222-
"because the operation timed out",
223-
[XName, Vhost])
221+
"Could not create ~ts because the operation "
222+
"timed out",
223+
[rabbit_misc:rs(XName)])
224224
end
225225
end,
226226
try rabbit_exchange:assert_equivalence(
@@ -300,8 +300,8 @@ handle_http_req(<<"DELETE">>,
300300
{error, timeout} ->
301301
throw(
302302
<<"503">>,
303-
"failed to delete exchange '~ts' due to a timeout",
304-
[XNameBin])
303+
"failed to delete ~ts due to a timeout",
304+
[rabbit_misc:rs(XName)])
305305
end;
306306

307307
handle_http_req(<<"POST">>,

deps/rabbit/src/rabbit_channel.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2581,9 +2581,9 @@ handle_method(#'exchange.declare'{exchange = XNameBin,
25812581
{error, timeout} ->
25822582
rabbit_misc:protocol_error(
25832583
internal_error,
2584-
"failed to declare exchange '~ts' in vhost '~ts' "
2585-
"because the operation timed out",
2586-
[XNameBinStripped, VHostPath])
2584+
"failed to declare ~ts because the operation "
2585+
"timed out",
2586+
[rabbit_misc:rs(ExchangeName)])
25872587
end
25882588
end,
25892589
ok = rabbit_exchange:assert_equivalence(X, CheckedType, Durable,

deps/rabbit/src/rabbit_logger_exchange_h.erl

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -148,18 +148,16 @@ wait_for_initial_pass(N) ->
148148
end.
149149

150150
setup_proc(
151-
#{config := #{exchange := #resource{name = Name,
152-
virtual_host = VHost}}} = Config) ->
151+
#{config := #{exchange := Exchange}} = Config) ->
153152
case declare_exchange(Config) of
154153
ok ->
155154
?LOG_INFO(
156-
"Logging to exchange '~ts' in vhost '~ts' ready", [Name, VHost],
155+
"Logging to ~ts ready", [rabbit_misc:rs(Exchange)],
157156
#{domain => ?RMQLOG_DOMAIN_GLOBAL});
158157
error ->
159158
?LOG_DEBUG(
160-
"Logging to exchange '~ts' in vhost '~ts' not ready, "
161-
"trying again in ~b second(s)",
162-
[Name, VHost, ?DECL_EXCHANGE_INTERVAL_SECS],
159+
"Logging to ~ts not ready, trying again in ~b second(s)",
160+
[rabbit_misc:rs(Exchange), ?DECL_EXCHANGE_INTERVAL_SECS],
163161
#{domain => ?RMQLOG_DOMAIN_GLOBAL}),
164162
receive
165163
stop -> ok
@@ -168,50 +166,45 @@ setup_proc(
168166
end
169167
end.
170168

171-
declare_exchange(
172-
#{config := #{exchange := #resource{name = Name,
173-
virtual_host = VHost} = Exchange}}) ->
169+
declare_exchange(#{config := #{exchange := Exchange}}) ->
174170
try rabbit_exchange:declare(
175171
Exchange, topic, true, false, true, [], ?INTERNAL_USER) of
176172
{ok, #exchange{}} ->
177173
?LOG_DEBUG(
178-
"Declared exchange '~ts' in vhost '~ts'",
179-
[Name, VHost],
174+
"Declared ~ts",
175+
[rabbit_misc:rs(Exchange)],
180176
#{domain => ?RMQLOG_DOMAIN_GLOBAL}),
181177
ok;
182178
{error, timeout} ->
183179
?LOG_DEBUG(
184-
"Could not declare exchange '~ts' in vhost '~ts' because the "
185-
"operation timed out",
186-
[Name, VHost],
180+
"Could not declare ~ts because the operation timed out",
181+
[rabbit_misc:rs(Exchange)],
187182
#{domain => ?RMQLOG_DOMAIN_GLOBAL}),
188183
error
189184
catch
190185
Class:Reason ->
191186
?LOG_DEBUG(
192-
"Could not declare exchange '~ts' in vhost '~ts', "
193-
"reason: ~0p:~0p",
194-
[Name, VHost, Class, Reason],
187+
"Could not declare ~ts, reason: ~0p:~0p",
188+
[rabbit_misc:rs(Exchange), Class, Reason],
195189
#{domain => ?RMQLOG_DOMAIN_GLOBAL}),
196190
error
197191
end.
198192

199193
unconfigure_exchange(
200-
#{config := #{exchange := #resource{name = Name,
201-
virtual_host = VHost} = Exchange,
194+
#{config := #{exchange := Exchange,
202195
setup_proc := Pid}}) ->
203196
Pid ! stop,
204197
case rabbit_exchange:ensure_deleted(Exchange, false, ?INTERNAL_USER) of
205198
ok ->
206199
ok;
207200
{error, timeout} ->
208201
?LOG_ERROR(
209-
"Could not delete exchange '~ts' in vhost '~ts' due to a timeout",
210-
[Name, VHost],
202+
"Could not delete ~ts due to a timeout",
203+
[rabbit_misc:rs(Exchange)],
211204
#{domain => ?RMQLOG_DOMAIN_GLOBAL}),
212205
ok
213206
end,
214207
?LOG_INFO(
215-
"Logging to exchange '~ts' in vhost '~ts' disabled",
216-
[Name, VHost],
208+
"Logging to ~ts disabled",
209+
[rabbit_misc:rs(Exchange)],
217210
#{domain => ?RMQLOG_DOMAIN_GLOBAL}).

0 commit comments

Comments
 (0)