Unable to create erlang manager from shell

I implemented gen_server and supervisor: test_server and test_sup . I want to test them from the shell / CLI. I wrote my start_link functions start_link that their names are registered locally.

I found that I can spawn test_server from the command line just fine, but spawned test_sup does not allow me to interact with the server at all.

For example, I can create test_server by doing:

 1> spawn(test_server, start_link, []). <0.39.0> 2> registered(). [...,test_server,...] 

I can interact with the server and everything looks fine.

However, if I try to do the same with test_sup , no new names / Pids will be registered in my "CLI process" (using registered/0 ). My test_server seems to have been spawned, but I can't interact with it (see Lucas Larsson's comment on SASL to see why this is).

I would suggest that I encoded the error in my supervisor, but this method of starting my supervisor works fine:

 1> {ok, Pid}= test_sup:start_link([]). {ok, <0.39.0>} 2> unlink(Pid). true 3> registered(). [...,test_server,test_sup,...] 

Why can I spawn gen_server but not a supervisor?


Update

The code I'm using can be found in this post . I use echo_server and echo_sup , two very simple modules.

Given this code, this works:

 spawn(echo_server, start_link, []). 

and this is not so:

 spawn(echo_sup, start_link, []). 
+4
source share
2 answers

This explanation was given by Bernard Duggan to the Erlang questions mailing list :

Related processes do not automatically die when the process with which they are connected exits with the code "normal". This is why [echo_server] does not exit when the outputs of a spawning process. So why does the supervisor die? The internal supervisory module is actually implemented as gen_server, but with process_flag (trap_exit, true). The result of this is that when the parent process dies, terminate () receives (which does not happen when trap_exit is disabled) and the dispatcher is disabled. This makes sense in the context of the observer, since the supervisor is spawned by his parent in the supervision tree - if it does not die every time its parent terminates, regardless of the reason, you would have hanging "branches" of the tree.

+1
source

Whenever you try to understand these things, it is usually very helpful to enable SASL.

applications :. Get started (SASL)

This way, you hopefully find out why your leader ends.

+3
source

Source: https://habr.com/ru/post/1309067/


All Articles