[erlang-questions] supervisor does not restart my worker

Jan Henry Nystrom jan@REDACTED
Sat Jun 9 14:36:25 CEST 2007


Hi Matej,

The whys and wherefores in this case is quite simple once
one has gotten used to Erlang and the failure model.
What happens is that your call to the server causes the
server to crash, which in turn makes your call to
gen_server:call to exit "with the same reason". Now
the thing that is unintuitive to the beginner happen, the supervisor
crashes because the supervisor is linked to the shell that crashes
since your call crashed. If you instead had called:
"catch serv:fail()."

the result would have been:

{'EXIT',{{{badmatch,2},[{serv,handle_call,3},{proc_lib,init_p,5}]},
          {gen_server,call,[serv,fail]}}}

but the server had not crashed and as a consequence not the supervisor
and as you had hoped the server had been restarted.

It is a common mistake to link things to the shell and then write
a simply typo and have everything crashing (that is linked to the shell
that is) as a result. It has happened to  me a to med all to often ;-)

/Cheers Henry
> 
> 
> 
> Matej Kosik wrote:
>> Hi,
>>
>> While playing with Erlang, I have tried to check supervisor behavior. 
>> I have written a simple generic server (it is attached as `serv.erl' 
>> file) that is started by a simple supervisor (its source is in the 
>> attached `sup.erl' file).
>>
>> The API of the server is simple:
>>
>>     serv:question()
>>     serv:fail()
>>
>> The second service intentionally fails. I wanted to see how the 
>> generic server is restarted so that I could continue using it (those 
>> services that does not cause failure). However, the `serv' worker is 
>> not restarted. What am I doing wrong?
>>
>>
>> <DETAILS>
>> I start supervisor as follows
>>
>>     1> sup:start_link().
>>
>> Then I try to use services of my server:
>>
>>     2> serv:question().
>>     42
>>     3> serv:question().
>>     42
>>
>> But when I call the service that causes failure of the server
>>
>>     4> serv:fail().
>>
>> I get
>>
>>     =ERROR REPORT==== 9-Jun-2007::13:34:51 ===
> [..]
>>                                sup,
>>                                []}
>>     ** Reason for termination ==
>>     ** {{{badmatch,2},[{serv,handle_call,3},{proc_lib,init_p,5}]},
>>         {gen_server,call,[serv,fail]}}
>>
>> and no restart happens.
>> </DETAILS>
>>
>> Thanks for any clues.
>> Cheers
>>
>>
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://www.erlang.org/mailman/listinfo/erlang-questions
> 
> 


-- 
Jan Henry Nystrom
Training Manager

Erlang Training and Consulting Ltd
401 Fruit and Wool Exchange,
Brushfield Street, London,
E1 6EL, United Kingdom
Company Registration 3893360 VAT Number GB 752 1091 57
Tel +44 207 456 1020
Fax +44 870 1390 779
jan@REDACTED



More information about the erlang-questions mailing list