aboutsummaryrefslogtreecommitdiffstats
path: root/src/ranch_server.erl
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2016-10-10 14:36:28 +0200
committerLoïc Hoguin <[email protected]>2016-10-10 14:36:28 +0200
commit61e0d3f7841257aad8c894b170941aa7bbad2a89 (patch)
tree0af877a53c4f156ce2ad72638d2c96575e396517 /src/ranch_server.erl
parent32d6d8def20a26342b2b2f908890b9cf50057efd (diff)
downloadranch-61e0d3f7841257aad8c894b170941aa7bbad2a89.tar.gz
ranch-61e0d3f7841257aad8c894b170941aa7bbad2a89.tar.bz2
ranch-61e0d3f7841257aad8c894b170941aa7bbad2a89.zip
Prevent a race condition when stopping listeners
In some cases the ranch_server:get_connections_sup/1 call could still succeed depending on timing.
Diffstat (limited to 'src/ranch_server.erl')
-rw-r--r--src/ranch_server.erl8
1 files changed, 8 insertions, 0 deletions
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.