Skip to content

Commit 7f200d8

Browse files
rabbit_misc:shutdown_supervisor/1: log on timeout, don't crash the caller rabbitmq#16598
1 parent 94c4e79 commit 7f200d8

5 files changed

Lines changed: 13 additions & 7 deletions

File tree

deps/rabbit/src/rabbit_channel_sup.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@
3838
rabbit_types:user(), rabbit_types:vhost(),
3939
rabbit_framing:amqp_table(), pid()}.
4040

41-
-define(FAIR_WAIT, 70000).
42-
4341
%%----------------------------------------------------------------------------
4442

4543
-spec start_link(start_link_args()) ->
@@ -63,6 +61,8 @@ start_link({tcp, Sock, Channel, FrameMax, ReaderPid, ConnName, User,
6361
shutdown => ?FAIR_WAIT,
6462
type => worker,
6563
modules => [rabbit_channel]},
64+
%% For potential backports to 4.1: this call site will need adjustment compared to 4.2 and newer series.
65+
%% Thread `Protocol` through `start_link_args/0` and `rabbit_command_assembler:init/1`.
6666
case supervisor:start_child(SupPid, ChildSpec) of
6767
{ok, ChannelPid} ->
6868
{ok, AState} = rabbit_command_assembler:init(),

deps/rabbit/test/channel_interceptor_SUITE.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,9 @@ conflicting_interceptors_close_direct_connections_gracefully1(Config) ->
277277
{ok, Conn} = amqp_connection:start(Params),
278278
?assert(is_pid(Conn)),
279279
?assert(is_process_alive(Conn)),
280-
%% open_channel must return {error, _} gracefully, not crash.
280+
%% `open_channel` must return `{error, _}` gracefully, not crash.
281281
%% If the connection process crashes (e.g. badmatch in
282-
%% amqp_channels_manager), this call will throw and fail the test.
282+
%% `amqp_channels_manager`), this call will throw and fail the test.
283283
Result = amqp_connection:open_channel(Conn),
284284
?assertMatch({error, _}, Result),
285285
?assert(is_process_alive(Conn)),

deps/rabbit_common/include/rabbit.hrl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@
226226
-define(EMPTY_FRAME_SIZE, 8).
227227

228228
-define(MAX_WAIT, 16#ffffffff).
229+
-define(FAIR_WAIT, 70_000).
229230
-define(SUPERVISOR_WAIT,
230231
rabbit_misc:get_env(rabbit, supervisor_shutdown_timeout, infinity)).
231232
-define(WORKER_WAIT,

deps/rabbit_common/include/rabbit_misc.hrl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@
77

88
-define(RPC_TIMEOUT, 15_000).
99
-define(RPC_INFINITE_TIMEOUT, infinity).
10-
-define(DEFAULT_TIMEOUT, 5_000).

deps/rabbit_common/src/rabbit_misc.erl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1436,14 +1436,20 @@ find_child(Supervisor, Name) ->
14361436
[Pid || {Name1, Pid, _Type, _Modules} <- supervisor:which_children(Supervisor),
14371437
Name1 =:= Name].
14381438

1439+
%% Must be called by the process that holds the link to SupPid.
1440+
-spec shutdown_supervisor(pid()) -> ok.
14391441
shutdown_supervisor(SupPid) when is_pid(SupPid) ->
14401442
MRef = erlang:monitor(process, SupPid),
14411443
unlink(SupPid),
14421444
exit(SupPid, shutdown),
14431445
receive
14441446
{'DOWN', MRef, process, SupPid, _} -> ok
1445-
after ?DEFAULT_TIMEOUT ->
1446-
exit({shutdown_supervisor_timeout, SupPid})
1447+
after ?FAIR_WAIT ->
1448+
erlang:demonitor(MRef, [flush]),
1449+
?LOG_WARNING(
1450+
"rabbit_misc:shutdown_supervisor/1 timed out waiting for ~tp to terminate",
1451+
[SupPid]),
1452+
ok
14471453
end.
14481454

14491455
%% -------------------------------------------------------------------------

0 commit comments

Comments
 (0)