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

Chandru chandrashekhar.mullaparthi@REDACTED
Fri May 13 15:47:17 CEST 2016


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 <Oliver.Korpilla@REDACTED> 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
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160513/ede739b6/attachment.htm>


More information about the erlang-questions mailing list