[erlang-questions] simple_one_for_one supervisor - what happens at restart? (also: gen_tcp)

Ryan Stewart <>
Sat May 14 01:59:41 CEST 2016


Oliver: there is no restart for children under a simple 1-1 supervisor as
documented under Supervision Principles at
http://erlang.org/doc/man/supervisor.html#id243029

Otoh, I have to strongly disagree with Chandru about there being "no point"
in supervising a connection process. Depending on the nature of your
application, there can be a *huge* benefit in supervision, which is orderly
shutdown. With a proper supervisory tree, you can ensure that all
connection processes have a chance to finish their work and shut down
cleanly when you stop your application.

On Fri, May 13, 2016 at 8:47 AM Chandru <
> wrote:

> Hi Oliver,
>
> There is no point supervising a process which is handling a TCP connection
> as even if the supervisor restarts this process, the socket will not be
> reinstated. You just have to spawn a new process which will stay alive as
> long as the connection is active. Once the TCP connection is lost, the
> process dies, and a new process is spawned when the client reconnects.
>
> See https://gist.github.com/cmullaparthi/18ba2219befbf7a3c44c28cab004456f
> for a barebones example.
>
> cheers,
> Chandru
>
> On 13 May 2016 at 14:25, Oliver Korpilla <> wrote:
>
>> Hello.
>>
>> I have transient workers under a simple_one_for_one supervisor. I start
>> them dynamically through start_child/2.
>>
>> How exactly do these get restarted? With the same parameter list I
>> supplied when first starting them?
>>
>> Concrete example:
>>
>> I have a central process listening to a TCP port, then accepting a
>> connection, creating a worker for it through a supervisor, and then using
>> gen_tcp:controlling_process/2 to transfer control of that new socket to the
>> worker. The worker starts with one parameter: the socket.
>>
>> Now lets say the worker crashes on unexpected input and gets restarted.
>> Is the socket now closed? Will the same socket again be provided to the
>> process on restart?
>>
>> Thanks,
>> Oliver
>> _______________________________________________
>> erlang-questions mailing list
>> 
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160513/f40c984c/attachment.html>


More information about the erlang-questions mailing list