diff options
author | juhlig <j.uhlig@mailingwork.de> | 2018-09-13 15:07:08 +0200 |
---|---|---|
committer | Loïc Hoguin <essen@ninenines.eu> | 2018-09-17 13:54:02 +0200 |
commit | fedc4af6432369850cb5e4b7aabfe0512ddfc5a5 (patch) | |
tree | df0f7dcf3f56ccd11d81774e7faa7f5f1f535206 | |
parent | cbe24f6fb9833474b22a06fc22cb1a8f168f7fbc (diff) | |
download | ranch-fedc4af6432369850cb5e4b7aabfe0512ddfc5a5.tar.gz ranch-fedc4af6432369850cb5e4b7aabfe0512ddfc5a5.tar.bz2 ranch-fedc4af6432369850cb5e4b7aabfe0512ddfc5a5.zip |
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.
-rw-r--r-- | src/ranch_server.erl | 14 |
1 files 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) -> |