aboutsummaryrefslogtreecommitdiffstats
path: root/src/ranch_listener_sup.erl
diff options
context:
space:
mode:
authorAndrew Majorov <[email protected]>2012-11-01 16:50:47 +0400
committerAndrew Majorov <[email protected]>2012-12-21 00:05:12 +0400
commit8dad1451dd6e41f30741ac7554da238aa63c163a (patch)
tree0be82b920136d309b0ca4fafb17d490ab048ae24 /src/ranch_listener_sup.erl
parent7f4261d1d83dde90be93d3615693b44969f6b446 (diff)
downloadranch-8dad1451dd6e41f30741ac7554da238aa63c163a.tar.gz
ranch-8dad1451dd6e41f30741ac7554da238aa63c163a.tar.bz2
ranch-8dad1451dd6e41f30741ac7554da238aa63c163a.zip
Make listener supervisor failures less painful
Two general issues were addressed. The first one is the issue with statically defined pids passed into childspecs. This issue prevents regular supervisor' children restarts in the case of someone's failure. The second one is the not quite appropriate restart strategy. Changed to rest_for_one which in pair with previous fixes assures that live connections will not die in the case of partial failure. Among possible failures are listening socket shutdown or frequent accept errors.
Diffstat (limited to 'src/ranch_listener_sup.erl')
-rw-r--r--src/ranch_listener_sup.erl36
1 files changed, 19 insertions, 17 deletions
diff --git a/src/ranch_listener_sup.erl b/src/ranch_listener_sup.erl
index c8ba12d..0147cf2 100644
--- a/src/ranch_listener_sup.erl
+++ b/src/ranch_listener_sup.erl
@@ -28,23 +28,25 @@
-> {ok, pid()}.
start_link(Ref, NbAcceptors, Transport, TransOpts, Protocol, ProtoOpts) ->
MaxConns = proplists:get_value(max_connections, TransOpts, 1024),
- {ok, SupPid} = supervisor:start_link(?MODULE, []),
- {ok, ListenerPid} = supervisor:start_child(SupPid,
- {ranch_listener, {ranch_listener, start_link,
- [Ref, MaxConns, ProtoOpts]},
- permanent, 5000, worker, [ranch_listener]}),
- ok = ranch_server:insert_listener(Ref, ListenerPid),
- {ok, ConnsPid} = supervisor:start_child(SupPid,
- {ranch_conns_sup, {ranch_conns_sup, start_link, []},
- permanent, 5000, supervisor, [ranch_conns_sup]}),
- {ok, _PoolPid} = supervisor:start_child(SupPid,
- {ranch_acceptors_sup, {ranch_acceptors_sup, start_link, [
- Ref, NbAcceptors, Transport, TransOpts,
- Protocol, ListenerPid, ConnsPid
- ]}, permanent, 5000, supervisor, [ranch_acceptors_sup]}),
- {ok, SupPid}.
+ supervisor:start_link(?MODULE, {
+ Ref, NbAcceptors, MaxConns, Transport, TransOpts, Protocol, ProtoOpts
+ }).
%% supervisor.
-init([]) ->
- {ok, {{one_for_all, 10, 10}, []}}.
+init({Ref, NbAcceptors, MaxConns, Transport, TransOpts, Protocol, ProtoOpts}) ->
+ ChildSpecs = [
+ %% listener
+ {ranch_listener, {ranch_listener, start_link,
+ [Ref, MaxConns, ProtoOpts]},
+ permanent, 5000, worker, [ranch_listener]},
+ %% conns_sup
+ {ranch_conns_sup, {ranch_conns_sup, start_link, [Ref]},
+ permanent, infinity, supervisor, [ranch_conns_sup]},
+ %% acceptors_sup
+ {ranch_acceptors_sup, {ranch_acceptors_sup, start_link,
+ [Ref, NbAcceptors, Transport, TransOpts, Protocol]
+ }, permanent, infinity, supervisor, [ranch_acceptors_sup]}
+ ],
+ {ok, {{rest_for_one, 10, 10}, ChildSpecs}}.
+