title: erlang OTP Supervisor crashing
body: <p>I'm working through the Erlang documentation, trying to understand the basics of setting up an OTP gen_server and supervisor. Whenever my gen_server crashes, my supervisor crashes as well. In fact, whenever I have an error on the command line, my supervisor crashes. </p>
  
  <p>I expect the gen_server to be restarted when it crashes. I expect command line errors to have <em>no bearing whatsoever</em> on my server components. My supervisor shouldn't be crashing at all.</p>
  
  <p>The code I'm working with is a basic "echo server" that replies with whatever you send in, and a supervisor that will restart the echo_server 5 times per minute at most (one_for_one).  My code:</p>
  
  <p><strong>echo_server.erl</strong></p>
  
  <pre><code>-module(echo_server).
  -behaviour(gen_server).
  
  -export([start_link/0]).
  -export([echo/1, crash/0]).
  -export([init/1, handle_call/3, handle_cast/2]).
  
  start_link() -&gt;
      gen_server:start_link({local, echo_server}, echo_server, [], []).
  
  %% public api
  echo(Text) -&gt;
      gen_server:call(echo_server, {echo, Text}).
  crash() -&gt;
      gen_server:call(echo_server, crash)..
  
  %% behaviours
  init(_Args) -&gt;
      {ok, none}.
  handle_call(crash, _From, State) -&gt;
      X=1,
      {reply, X=2, State}.
  handle_call({echo, Text}, _From, State) -&gt;
      {reply, Text, State}.
  handle_cast(_, State) -&gt;
      {noreply, State}.
  </code></pre>
  
  <p><strong>echo_sup.erl</strong></p>
  
  <pre><code>-module(echo_sup).
  -behaviour(supervisor).
  -export([start_link/0]).
  -export([init/1]).
  
  start_link() -&gt;
      supervisor:start_link(echo_sup, []).
  init(_Args) -&gt;
      {ok,  {{one_for_one, 5, 60},
         [{echo_server, {echo_server, start_link, []},
               permanent, brutal_kill, worker, [echo_server]}]}}.
  </code></pre>
  
  <p>Compiled using <code>erlc *.erl</code>, and here's a sample run:</p>
  
  <pre><code>Erlang R13B01 (erts-5.7.2) [source] [smp:2:2] [rq:2] [async-threads:0] [kernel-p
  oll:false]
  
  Eshell V5.7.2  (abort with ^G)
  1&gt; echo_sup:start_link().
  {ok,&lt;0.37.0&gt;}
  2&gt; echo_server:echo("hi").
  "hi"
  3&gt; echo_server:crash().   
  
  =ERROR REPORT==== 5-May-2010::10:05:54 ===
  ** Generic server echo_server terminating 
  ** Last message in was crash
  ** When Server state == none
  ** Reason for termination == 
  ** {'function not exported',
         [{echo_server,terminate,
              [{{badmatch,2},
                [{echo_server,handle_call,3},
                 {gen_server,handle_msg,5},
                 {proc_lib,init_p_do_apply,3}]},
               none]},
          {gen_server,terminate,6},
          {proc_lib,init_p_do_apply,3}]}
  
  =ERROR REPORT==== 5-May-2010::10:05:54 ===
  ** Generic server &lt;0.37.0&gt; terminating 
  ** Last message in was {'EXIT',&lt;0.35.0&gt;,
                             {{{undef,
                                   [{echo_server,terminate,
                                        [{{badmatch,2},
                                          [{echo_server,handle_call,3},
                                           {gen_server,handle_msg,5},
                                           {proc_lib,init_p_do_apply,3}]},
                                         none]},
                                    {gen_server,terminate,6},
                                    {proc_lib,init_p_do_apply,3}]},
                               {gen_server,call,[echo_server,crash]}},
                              [{gen_server,call,2},
                               {erl_eval,do_apply,5},
                               {shell,exprs,6},
                               {shell,eval_exprs,6},
                               {shell,eval_loop,3}]}}
  ** When Server state == {state,
                              {&lt;0.37.0&gt;,echo_sup},
                              one_for_one,
                              [{child,&lt;0.41.0&gt;,echo_server,
                                   {echo_server,start_link,[]},
                                   permanent,brutal_kill,worker,
                                   [echo_server]}],
                              {dict,0,16,16,8,80,48,
                                  {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],
                                   []},
                                  {{[],[],[],[],[],[],[],[],[],[],[],[],[],[],
                                    [],[]}}},
                              5,60,
                              [{1273,79154,701110}],
                              echo_sup,[]}
  ** Reason for termination == 
  ** {{{undef,[{echo_server,terminate,
                            [{{badmatch,2},
                              [{echo_server,handle_call,3},
                               {gen_server,handle_msg,5},
                               {proc_lib,init_p_do_apply,3}]},
                             none]},
               {gen_server,terminate,6},
               {proc_lib,init_p_do_apply,3}]},
       {gen_server,call,[echo_server,crash]}},
      [{gen_server,call,2},
       {erl_eval,do_apply,5},
       {shell,exprs,6},
       {shell,eval_exprs,6},
       {shell,eval_loop,3}]}
  ** exception exit: {{undef,
                          [{echo_server,terminate,
                               [{{badmatch,2},
                                 [{echo_server,handle_call,3},
                                  {gen_server,handle_msg,5},
                                  {proc_lib,init_p_do_apply,3}]},
                                none]},
                           {gen_server,terminate,6},
                           {proc_lib,init_p_do_apply,3}]},
                      {gen_server,call,[echo_server,crash]}}
       in function  gen_server:call/2
  4&gt; echo_server:echo("hi").
  ** exception exit: {noproc,{gen_server,call,[echo_server,{echo,"hi"}]}}
       in function  gen_server:call/2
  5&gt;
  </code></pre>