<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Feb 8, 2015 at 5:52 AM, Harit Himanshu <span dir="ltr"><<a href="mailto:harit.subscriptions@gmail.com" target="_blank">harit.subscriptions@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div>My question is following</div><div><ol><li>How does killing of controlling process affect the process owned by Listen</li><li>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)?</li></ol></div></blockquote></div><br>The ListenSock has a ListenProcess. An AcceptProcess calling {ok, ASock} = gen_tcp:accept(ListenSock) creates a new socket, ASock. The control rules are:</div><div class="gmail_extra"><br></div><div class="gmail_extra">ListenProcess controls ListenSock</div><div class="gmail_extra">AcceptProcess controls ASock</div><div class="gmail_extra"><br></div><div class="gmail_extra">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.</div><div class="gmail_extra"><br></div><div class="gmail_extra">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.</div><div class="gmail_extra"><br></div><div class="gmail_extra">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.</div><div class="gmail_extra"><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">J.</div>
</div></div>