Browse Source

Prevent a race condition when stopping listeners

In some cases the ranch_server:get_connections_sup/1 call could
still succeed depending on timing.
Loïc Hoguin 8 years ago
parent
commit
61e0d3f784
1 changed files with 8 additions and 0 deletions
  1. 8 0
      src/ranch_server.erl

+ 8 - 0
src/ranch_server.erl

@@ -59,6 +59,14 @@ cleanup_listener_opts(Ref) ->
 	_ = ets:delete(?TAB, {addr, Ref}),
 	_ = ets:delete(?TAB, {max_conns, Ref}),
 	_ = ets:delete(?TAB, {opts, Ref}),
+	%% We also remove the pid of the connections supervisor.
+	%% Depending on the timing, it might already have been deleted
+	%% when we handled the monitor DOWN message. However, in some
+	%% cases when calling stop_listener followed by get_connections_sup,
+	%% we could end up with the pid still being returned, when we
+	%% expected a crash (because the listener was stopped).
+	%% Deleting it explictly here removes any possible confusion.
+	_ = ets:delete(?TAB, {conns_sup, Ref}),
 	ok.
 
 -spec set_connections_sup(ranch:ref(), pid()) -> ok.