From 8dad1451dd6e41f30741ac7554da238aa63c163a Mon Sep 17 00:00:00 2001 From: Andrew Majorov Date: Thu, 1 Nov 2012 16:50:47 +0400 Subject: 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. --- src/ranch_conns_sup.erl | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/ranch_conns_sup.erl') diff --git a/src/ranch_conns_sup.erl b/src/ranch_conns_sup.erl index 99853c5..3cc09be 100644 --- a/src/ranch_conns_sup.erl +++ b/src/ranch_conns_sup.erl @@ -17,7 +17,7 @@ -behaviour(supervisor). %% API. --export([start_link/0]). +-export([start_link/1]). -export([start_protocol/5]). %% supervisor. @@ -25,9 +25,9 @@ %% API. --spec start_link() -> {ok, pid()}. -start_link() -> - supervisor:start_link(?MODULE, []). +-spec start_link(any()) -> {ok, pid()}. +start_link(Ref) -> + supervisor:start_link(?MODULE, Ref). -spec start_protocol(pid(), inet:socket(), module(), module(), any()) -> {ok, pid()}. @@ -36,6 +36,7 @@ start_protocol(ListenerPid, Socket, Transport, Protocol, Opts) -> %% supervisor. -init([]) -> +init(Ref) -> + ok = ranch_server:set_connections_sup(Ref, self()), {ok, {{simple_one_for_one, 0, 1}, [{?MODULE, {?MODULE, start_protocol, []}, temporary, brutal_kill, worker, [?MODULE]}]}}. -- cgit v1.2.3