Browse Source

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.
juhlig 6 years ago
parent
commit
fedc4af643
1 changed files with 12 additions and 2 deletions
  1. 12 2
      src/ranch_server.erl

+ 12 - 2
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) ->