[erlang-questions] gen_tcp under gen_server design

Andre Nathan <>
Wed Aug 4 21:38:27 CEST 2010

On Fri, 2010-07-30 at 11:57 -0500, Logan, Martin wrote:
> Once you accept call into the simple_one_for_one supervisor that is
> responsible for spawning off your acceptors and have it spawn another
> one to wait for the next connection while the first chugs along
> processing on a socket it already owns by virtue of the fact that it
> accepted it. There is no worry here between accepting one connection
> and spawning another to accept the next because the OS queues up
> pending connections of which the call to accept/1 only pulls off the
> first one.

How do you handle the case where this newly spawned acceptor dies? One
would want to assert that there's always one acceptor blocked in
gen_tcp:accept and that it is restarted if it dies, so that new
connections are not refused. The processes that return from accept,
though, shouldn't be restarted because if they die their connection will
be closed, so it doesn't make sense to restart them. Since they're all
under the same simple_one_for_one supervisor, I'm not sure how to
specify that only the currently blocked acceptor must be restarted.

I guess that if I need this level of control, I should keep a
'permanent' acceptor under one supervisor and spawn workers as needed
from a simple_one_for_one supervisor, right? This would be the opposite
of the "spawn a new acceptor" idiom that you describe in your book.


More information about the erlang-questions mailing list