<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><span style="font-family:Arial,Helvetica,sans-serif">On Thu, Nov 19, 2020 at 12:27 AM George Hope <<a href="mailto:george@1w1g.com">george@1w1g.com</a>> wrote:</span><br></div></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><u></u><div><div style="font-family:Verdana,Arial,Helvetica,sans-serif;font-size:10pt"><div>I have a simple gen_server which connects to a tcp port, when I run gen_server directly:<br></div><div>erl -noshell  -s ttest start<br></div><div>it works fine, But when I run:<br></div><div>erl -noshell -s tt_sup start_link <br></div><div>the connection will be closed instantly, it will work if I unlink the supervisor.<br></div><div>How could I run my simple gen_server with supervisor ?<br></div><div><br></div></div></div></blockquote><div><br></div><div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">In the normal setup, supervisors have parents, and those parents are linked such that errors in one end of the supervisor tree propagates. Supervisors trap exit, so they have a way to stop that propagation, based on their configuration. My guess is that when you run your program, the Erlang VM spawns a process to handle your `-s` command. This process exits, and that will reap your supervisor as well.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">The right way of solving this is to start using applications. An application has a top-level supervisor which is then handled by the application manager in the system, and thus not being shut down as long as the VM is running. It's a bit of a curve-ball I'm throwing you, I'm afraid. Applications are far more involved to set up (and it leads into creating releases as well, which is a subject of its own. Rebar3/Relx makes it easier, but do note it isn't a simple process). On the other hand, as your toy program is growing, it is likely to benefit more and more from doing it right, so even if the ball curves a lot, you might end up catching it. There is a point where switching to the application structure would be more beneficial. If you are experienced as an erlang developer, I'm guessing you just create the app straight away, but if you are less experienced, people tend to look for the solutions found in other languages, and it doesn't work as well.</div><br></div></div></div>