From fedc4af6432369850cb5e4b7aabfe0512ddfc5a5 Mon Sep 17 00:00:00 2001 From: juhlig Date: Thu, 13 Sep 2018 15:07:08 +0200 Subject: Clean listener options after normal shutdown In addition to cleaning when ranch:stop_listener/1 is called, we also need to clean when we detect the supervisor is going away for normal reasons, because the supervisor might be in another application's supervision tree. Note that there might be a short delay in this case before the cleanup is done, due to using monitors for detection. --- src/ranch_server.erl | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/ranch_server.erl b/src/ranch_server.erl index 015c9f9..38eb0c6 100644 --- a/src/ranch_server.erl +++ b/src/ranch_server.erl @@ -203,10 +203,20 @@ handle_call(_Request, _From, State) -> handle_cast(_Request, State) -> {noreply, State}. -handle_info({'DOWN', MonitorRef, process, Pid, _}, +handle_info({'DOWN', MonitorRef, process, Pid, Reason}, State=#state{monitors=Monitors}) -> {_, TypeRef} = lists:keyfind({MonitorRef, Pid}, 1, Monitors), - _ = ets:delete(?TAB, TypeRef), + ok = case {TypeRef, Reason} of + {{listener_sup, Ref}, normal} -> + cleanup_listener_opts(Ref); + {{listener_sup, Ref}, shutdown} -> + cleanup_listener_opts(Ref); + {{listener_sup, Ref}, {shutdown, _}} -> + cleanup_listener_opts(Ref); + _ -> + _ = ets:delete(?TAB, TypeRef), + ok + end, Monitors2 = lists:keydelete({MonitorRef, Pid}, 1, Monitors), {noreply, State#state{monitors=Monitors2}}; handle_info(_Info, State) -> -- cgit v1.2.3