From 61e0d3f7841257aad8c894b170941aa7bbad2a89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 10 Oct 2016 14:36:28 +0200 Subject: Prevent a race condition when stopping listeners In some cases the ranch_server:get_connections_sup/1 call could still succeed depending on timing. --- src/ranch_server.erl | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/ranch_server.erl') diff --git a/src/ranch_server.erl b/src/ranch_server.erl index 3bb6163..4aa858d 100644 --- a/src/ranch_server.erl +++ b/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. -- cgit v1.2.3