[erlang-questions] Question on building a Parallel Server

Harit Himanshu harit.subscriptions@REDACTED
Sun Feb 8 18:25:21 CET 2015

Thanks @Jesper for detailed explanation
+ Harit

On Sun, Feb 8, 2015 at 7:35 AM, Jesper Louis Andersen <
jesper.louis.andersen@REDACTED> wrote:

> On Sun, Feb 8, 2015 at 5:52 AM, Harit Himanshu <
> harit.subscriptions@REDACTED> wrote:
>> My question is following
>>    1. How does killing of controlling process affect the process owned
>>    by Listen
>>    2. If we reverse this approach, how does killing of process (which
>>    owns Listen) affects n controlling processes (for n different Sockets
>>    associated with this Listen process)?
> The ListenSock has a ListenProcess. An AcceptProcess calling {ok, ASock} =
> gen_tcp:accept(ListenSock) creates a new socket, ASock. The control rules
> are:
> ListenProcess controls ListenSock
> AcceptProcess controls ASock
> Termination of ListenProcess will affect the socket directly under its
> control, ListenSock, but will not touch ASock. Vice versa, termination of
> AcceptProcess will close ASock, but not affect ListenSock in any way. In
> other words, the two sockets bear no relation to each other, other than one
> was used to create the other.
> There are some caveats to look out for, however. Often, you run the
> Listener in one process, away from workers since it protects the system.
> And error in one part doesn't affect the other part. Once a listen socket
> closes, the operating system doesn't let you reuse that socket immediately,
> but imposes a "linger time" in which you can't rebind to the Address/Port
> combination. The reason for the lingering is to make sure drain happens
> such that you don't inadvertedly connect up incorrectly. You may want to
> enable the SO_REUSEADDR socket option, which is done in Erlang by creating
> the listen socket with the {reuseaddr, true} option. It does other things
> than just solve the lingering problem however, and exactly what it does is
> OS dependent.
> The best solution is to trust the ListenProcess more than the workers.
> That is, place the ListenProcess higher up in the supervisor tree and make
> its death be fatal to the system. If the operating system suddenly denies
> you access to the Listen socket, chances are you have a major problem.
> --
> J.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150208/45e3bb20/attachment.htm>

More information about the erlang-questions mailing list