From 96fcb3f864f787fd3d74f20189eed7a1aba81cb4 Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Tue, 15 Nov 2011 11:27:58 +0100 Subject: Add env var shutdown_timeout to kernel to avoid deadlock on node shutdown When a node is shutting down, application_controller will do exit(Pid,shutdown) on all application masters, and wait for {'EXIT',Pid,_}. If, for some reason, the application master does not terminate then application_controller will hang forever waiting for this 'EXIT' message. To overcome this problem, a configurable timer is added to kernel - the enviroment variable 'shutdown_timeout'. If this variable is set to a positive integer T, application_controller will do exit(Pid,kill) after T milli seconds if no 'EXIT' message is received. --- lib/kernel/src/application_controller.erl | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'lib/kernel') diff --git a/lib/kernel/src/application_controller.erl b/lib/kernel/src/application_controller.erl index 42f527f400..ebfe84463a 100644 --- a/lib/kernel/src/application_controller.erl +++ b/lib/kernel/src/application_controller.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2010. All Rights Reserved. +%% Copyright Ericsson AB 1996-2011. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -1180,10 +1180,27 @@ terminate(Reason, S) -> _ -> ok end, + ShutdownTimeout = + case application:get_env(kernel, shutdown_timeout) of + undefined -> infinity; + {ok,T} -> T + end, foreach(fun({_AppName, Id}) when is_pid(Id) -> + Ref = erlang:monitor(process, Id), + unlink(Id), exit(Id, shutdown), receive + %% Proc died before link {'EXIT', Id, _} -> ok + after 0 -> + receive + {'DOWN', Ref, process, Id, _} -> ok + after ShutdownTimeout -> + exit(Id, kill), + receive + {'DOWN', Ref, process, Id, _} -> ok + end + end end; (_) -> ok end, -- cgit v1.2.3