Skip to content

Commit a48d0de

Browse files
committed
Fix Cowboy crashes caused by double reply
Issue introduced in 383ddb1.
1 parent 28a407c commit a48d0de

File tree

3 files changed

+41
-33
lines changed

3 files changed

+41
-33
lines changed

deps/rabbitmq_management/src/rabbit_mgmt_wm_exchange_publish.erl

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ content_types_provided(ReqData, Context) ->
3030
{rabbit_mgmt_util:responder_map(to_json), ReqData, Context}.
3131

3232
resource_exists(ReqData, Context) ->
33-
{case rabbit_mgmt_wm_exchange:exchange(ReqData) of
34-
not_found -> raise_not_found(ReqData, Context);
35-
_ -> true
36-
end, ReqData, Context}.
33+
case rabbit_mgmt_wm_queue:queue(ReqData) of
34+
not_found -> {false, set_resp_not_found(ReqData), Context};
35+
_ -> {true, ReqData, Context}
36+
end.
3737

3838
allow_missing_post(ReqData, Context) ->
3939
{false, ReqData, Context}.
@@ -104,17 +104,19 @@ bad({{coordinator_unavailable, _}, _}, ReqData, Context) ->
104104
is_authorized(ReqData, Context) ->
105105
rabbit_mgmt_util:is_authorized_vhost(ReqData, Context).
106106

107-
raise_not_found(ReqData, Context) ->
107+
set_resp_not_found(ReqData) ->
108108
ErrorMessage = case rabbit_mgmt_util:vhost(ReqData) of
109109
not_found ->
110-
"vhost_not_found";
110+
<<"vhost_not_found">>;
111111
_ ->
112-
"exchange_not_found"
112+
<<"exchange_not_found">>
113113
end,
114-
rabbit_mgmt_util:not_found(
115-
rabbit_data_coercion:to_binary(ErrorMessage),
116-
ReqData,
117-
Context).
114+
ReqData1 = cowboy_req:set_resp_header(
115+
<<"content-type">>, <<"application/json">>, ReqData),
116+
cowboy_req:set_resp_body(rabbit_json:encode(#{
117+
<<"error">> => <<"not_found">>,
118+
<<"reason">> => ErrorMessage
119+
}), ReqData1).
118120

119121
%%--------------------------------------------------------------------
120122

deps/rabbitmq_management/src/rabbit_mgmt_wm_queue_actions.erl

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ allowed_methods(ReqData, Context) ->
2626
{[<<"POST">>, <<"OPTIONS">>], ReqData, Context}.
2727

2828
resource_exists(ReqData, Context) ->
29-
{case rabbit_mgmt_wm_queue:queue(ReqData) of
30-
not_found -> raise_not_found(ReqData, Context);
31-
_ -> true
32-
end, ReqData, Context}.
29+
case rabbit_mgmt_wm_queue:queue(ReqData) of
30+
not_found -> {false, set_resp_not_found(ReqData), Context};
31+
_ -> {true, ReqData, Context}
32+
end.
3333

3434
allow_missing_post(ReqData, Context) ->
3535
{false, ReqData, Context}.
@@ -54,17 +54,20 @@ do_it(ReqData0, Context) ->
5454
is_authorized(ReqData, Context) ->
5555
rabbit_mgmt_util:is_authorized_admin(ReqData, Context).
5656

57-
raise_not_found(ReqData, Context) ->
57+
set_resp_not_found(ReqData) ->
5858
ErrorMessage = case rabbit_mgmt_util:vhost(ReqData) of
5959
not_found ->
60-
"vhost_not_found";
60+
<<"vhost_not_found">>;
6161
_ ->
62-
"queue_not_found"
62+
<<"queue_not_found">>
6363
end,
64-
rabbit_mgmt_util:not_found(
65-
rabbit_data_coercion:to_binary(ErrorMessage),
66-
ReqData,
67-
Context).
64+
ReqData1 = cowboy_req:set_resp_header(
65+
<<"content-type">>, <<"application/json">>, ReqData),
66+
cowboy_req:set_resp_body(rabbit_json:encode(#{
67+
<<"error">> => <<"not_found">>,
68+
<<"reason">> => ErrorMessage
69+
}), ReqData1).
70+
6871
%%--------------------------------------------------------------------
6972

7073
action(Else, _Q, ReqData, Context) ->

deps/rabbitmq_management/src/rabbit_mgmt_wm_queue_get.erl

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ content_types_provided(ReqData, Context) ->
3030
{rabbit_mgmt_util:responder_map(to_json), ReqData, Context}.
3131

3232
resource_exists(ReqData, Context) ->
33-
{case rabbit_mgmt_wm_queue:queue(ReqData) of
34-
not_found -> raise_not_found(ReqData, Context);
35-
_ -> true
36-
end, ReqData, Context}.
33+
case rabbit_mgmt_wm_queue:queue(ReqData) of
34+
not_found -> {false, set_resp_not_found(ReqData), Context};
35+
_ -> {true, ReqData, Context}
36+
end.
3737

3838
allow_missing_post(ReqData, Context) ->
3939
{false, ReqData, Context}.
@@ -152,17 +152,20 @@ basic_get(Ch, Q, AckMode, Enc, Trunc) ->
152152
is_authorized(ReqData, Context) ->
153153
rabbit_mgmt_util:is_authorized_vhost(ReqData, Context).
154154

155-
raise_not_found(ReqData, Context) ->
155+
set_resp_not_found(ReqData) ->
156156
ErrorMessage = case rabbit_mgmt_util:vhost(ReqData) of
157157
not_found ->
158-
"vhost_not_found";
158+
<<"vhost_not_found">>;
159159
_ ->
160-
"queue_not_found"
160+
<<"queue_not_found">>
161161
end,
162-
rabbit_mgmt_util:not_found(
163-
rabbit_data_coercion:to_binary(ErrorMessage),
164-
ReqData,
165-
Context).
162+
ReqData1 = cowboy_req:set_resp_header(
163+
<<"content-type">>, <<"application/json">>, ReqData),
164+
cowboy_req:set_resp_body(rabbit_json:encode(#{
165+
<<"error">> => <<"not_found">>,
166+
<<"reason">> => ErrorMessage
167+
}), ReqData1).
168+
166169
%%--------------------------------------------------------------------
167170

168171
maybe_truncate(Payload, none) -> Payload;

0 commit comments

Comments
 (0)