Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would suggest you to <em>debug/trace</em> your application to check what's going on. It's very helpful in understanding how things work in OTP.</p> <p>In your case, you might want to do the following.</p> <p>Start the tracer:</p> <pre><code>dbg:tracer(). </code></pre> <p>Trace all function calls for your supervisor and your gen_server:</p> <pre><code>dbg:p(all,c). dbg:tpl(echo_server, x). dbg:tpl(echo_sup, x). </code></pre> <p>Check which messages the processes are passing:</p> <pre><code>dbg:p(new, m). </code></pre> <p>See what's happening to your processes (crash, etc):</p> <pre><code>dbg:p(new, p). </code></pre> <p>For more information about tracing:</p> <p><a href="http://www.erlang.org/doc/man/dbg.html" rel="nofollow noreferrer">http://www.erlang.org/doc/man/dbg.html</a></p> <p><a href="http://aloiroberto.wordpress.com/2009/02/23/tracing-erlang-functions/" rel="nofollow noreferrer">http://aloiroberto.wordpress.com/2009/02/23/tracing-erlang-functions/</a></p> <p>Hope this can help for this and future situations.</p> <p><strong>HINT:</strong> The gen_server behaviour is expecting the callback terminate/2 to be defined and exported ;)</p> <p><strong>UPDATE:</strong> After the definition of the <em>terminate/2</em> the reason of the crash is evident from the trace. This is how it looks:</p> <p>We (75) call the crash/0 function. This is received by the gen_server (78).</p> <pre><code>(&lt;0.75.0&gt;) call echo_server:crash() (&lt;0.75.0&gt;) &lt;0.78.0&gt; ! {'$gen_call',{&lt;0.75.0&gt;,#Ref&lt;0.0.0.358&gt;},crash} (&lt;0.78.0&gt;) &lt;&lt; {'$gen_call',{&lt;0.75.0&gt;,#Ref&lt;0.0.0.358&gt;},crash} (&lt;0.78.0&gt;) call echo_server:handle_call(crash,{&lt;0.75.0&gt;,#Ref&lt;0.0.0.358&gt;},none) </code></pre> <p>Uh, problem on the handle call. We have a badmatch...</p> <pre><code>(&lt;0.78.0&gt;) exception_from {echo_server,handle_call,3} {error,{badmatch,2}} </code></pre> <p><strong>The terminate function is called</strong>. The server exits and it gets unregistered.</p> <pre><code>(&lt;0.78.0&gt;) call echo_server:terminate({{badmatch,2}, [{echo_server,handle_call,3}, {gen_server,handle_msg,5}, {proc_lib,init_p_do_apply,3}]},none) (&lt;0.78.0&gt;) returned from echo_server:terminate/2 -&gt; ok (&lt;0.78.0&gt;) exit {{badmatch,2}, [{echo_server,handle_call,3}, {gen_server,handle_msg,5}, {proc_lib,init_p_do_apply,3}]} (&lt;0.78.0&gt;) unregister echo_server </code></pre> <p>The Supervisor (77) receive the exit signal from the gen_server and it does its job:</p> <pre><code>(&lt;0.77.0&gt;) &lt;&lt; {'EXIT',&lt;0.78.0&gt;, {{badmatch,2}, [{echo_server,handle_call,3}, {gen_server,handle_msg,5}, {proc_lib,init_p_do_apply,3}]}} (&lt;0.77.0&gt;) getting_unlinked &lt;0.78.0&gt; (&lt;0.75.0&gt;) &lt;&lt; {'DOWN',#Ref&lt;0.0.0.358&gt;,process,&lt;0.78.0&gt;, {{badmatch,2}, [{echo_server,handle_call,3}, {gen_server,handle_msg,5}, {proc_lib,init_p_do_apply,3}]}} (&lt;0.77.0&gt;) call echo_server:start_link() </code></pre> <p>Well, it tries... Since it happens what Filippo said...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload