Hi Evan,
I have a similar problem. I am trying to get a background process up and running bu I was unable todoo,ithas alwazs terminated )and in case I ran a supervisor, the children always crashed.
Let's assume the following, there is a simple loop like this (i use this for testing):
loop_link() ->
Pid=spawn_link(?MODULE,loop,[]),
erlang:unlink(Pid),
{ok, Pid}
.
loop() ->
receive
_ ->
?MODULE:loop()
after 1000 ->
io:format("a~n"),
?MODULE:loop()
end
.
I have tried with spawn, spawn_link with unlink, everything.The result is the same, here is a log of a sample run (init-dev):
task_supervisor2:loop_link()
(leader@dom0)1> .
{ok,<0.432.0>}
a
a
a
(leader@dom0)2> 23:02:46.724 [info] Loading routes from "/home/mpeter/cc_dev/cb/cc_webui/priv/cc_webui.routes" ....
a
(leader@dom0)2> 23:02:47.268 [info] Loading routes from "/home/mpeter/cc_dev/cb/cc_webui/priv/cc_webui.routes" ....
23:02:47.271 [info] GET / [cc_webui] 200 547ms
23:02:47.284 [error] Error in process <0.437.0> on node 'leader@dom0' with exit value: {{case_clause,closed},[{cowboy_protocol,execute,4,[{file,"src/cowboy_protocol.erl"},{line,514}]}]}
23:02:47.372 [error] Supervisor ranch_conns_sup had child ranch_conns_sup started with {ranch_conns_sup,start_protocol,undefined} at <0.437.0> exit with reason no case clause matching closed in cowboy_protocol:execute/4 line 514 in context child_terminated
a
(leader@dom0)2> 23:02:47.823 [info] GET / [cc_webui] 200 554ms
a
a
(leader@dom0)2> 23:02:49.900 [info] Loading routes from "/home/mpeter/cc_dev/cb/cc_webui/priv/cc_webui.routes" ....
23:02:50.403 [info] Loading routes from "/home/mpeter/cc_dev/cb/cc_webui/priv/cc_webui.routes" ....
23:02:50.447 [info] GET / [cc_webui] 200 548ms
23:02:50.448 [error] Error in process <0.453.0> on node 'leader@dom0' with exit value: {{case_clause,closed},[{cowboy_protocol,execute,4,[{file,"src/cowboy_protocol.erl"},{line,514}]}]}
23:02:50.495 [error] Supervisor ranch_conns_sup had child ranch_conns_sup started with {ranch_conns_sup,start_protocol,undefined} at <0.453.0> exit with reason no case clause matching closed in cowboy_protocol:execute/4 line 514 in context child_terminated
23:02:50.956 [info] GET / [cc_webui] 200 553ms
...
letme explain: it works as long as I click on pages and wait until they are loaded. But once I click fast (without waiting for the previous page to load), it will just kill the process after a couple of clicks.... A supervisor wont really help because I need a lot of backgound processes and their startup is kind of heavy, it is not an option to mas-restart them whenever a user starts to click on links fast..
What is the proper way of handling this? I need a lot of bg processes representing entities that run reliably in the background no matter what happens to the frontend (ok, actually it can crass if boss crashes completely but it should crash on a regular basis).
Thank you for your help in advance!
Best regards,
Peter Molnar
Peter