Skip to content

Commit f44c851

Browse files
committed
Fix crash when closing connection
Avoid the following crash ``` ** Reason for termination == ** {mqtt_unexpected_cast,{shutdown,"Closed via management plugin"}} crasher: initial call: rabbit_mqtt_reader:init/1 pid: <0.1096.0> registered_name: [] exception exit: {mqtt_unexpected_cast, {shutdown,"Closed via management plugin"}} in function gen_server:handle_common_reply/8 (gen_server.erl, line 1208) ``` when closing MQTT or Stream connections via HTTP API endpoint ``` /connections/username/:username ```
1 parent 69944d2 commit f44c851

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

deps/rabbitmq_management/src/rabbit_mgmt_wm_connection_user_name.erl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ force_close_connection(ReqData, Conn, Pid) ->
8585
network ->
8686
rabbit_networking:close_connection(Pid, Reason);
8787
_ ->
88-
% best effort, this will work for connections to the stream plugin
89-
gen_server:cast(Pid, {shutdown, Reason})
90-
end,
91-
ok.
88+
%% Best effort will work for following plugins:
89+
%% rabbitmq_stream, rabbitmq_mqtt, rabbitmq_web_mqtt
90+
_ = Pid ! {shutdown, Reason},
91+
ok
92+
end.

deps/rabbitmq_mqtt/test/shared_SUITE.erl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,19 +1217,27 @@ management_plugin_connection(Config) ->
12171217
KeepaliveSecs = 99,
12181218
ClientId = atom_to_binary(?FUNCTION_NAME),
12191219
Node = atom_to_binary(get_node_config(Config, 0, nodename)),
1220-
C = connect(ClientId, Config, [{keepalive, KeepaliveSecs}]),
12211220

1221+
C1 = connect(ClientId, Config, [{keepalive, KeepaliveSecs}]),
12221222
eventually(?_assertEqual(1, length(http_get(Config, "/connections"))), 1000, 10),
12231223
[#{client_properties := #{client_id := ClientId},
12241224
timeout := KeepaliveSecs,
12251225
node := Node,
12261226
name := ConnectionName}] = http_get(Config, "/connections"),
1227-
12281227
process_flag(trap_exit, true),
12291228
http_delete(Config,
12301229
"/connections/" ++ binary_to_list(uri_string:quote((ConnectionName))),
12311230
?NO_CONTENT),
1232-
await_exit(C),
1231+
await_exit(C1),
1232+
?assertEqual([], http_get(Config, "/connections")),
1233+
eventually(?_assertEqual([], all_connection_pids(Config)), 500, 3),
1234+
1235+
C2 = connect(ClientId, Config, [{keepalive, KeepaliveSecs}]),
1236+
eventually(?_assertEqual(1, length(http_get(Config, "/connections"))), 1000, 10),
1237+
http_delete(Config,
1238+
"/connections/username/guest",
1239+
?NO_CONTENT),
1240+
await_exit(C2),
12331241
?assertEqual([], http_get(Config, "/connections")),
12341242
eventually(?_assertEqual([], all_connection_pids(Config)), 500, 3).
12351243

0 commit comments

Comments
 (0)