What's wrong with this ???

Chandrashekhar Mullaparthi <>
Mon Jun 2 16:51:22 CEST 2003


Joe,

That is because your supervisor itself is linked to the shell, which dies
when you call kv:lookup(crash)

cheers
Chandru

-----Original Message-----
From: Joe Armstrong [mailto:]
Sent: 02 June 2003 15:25
To: 
Subject: What's wrong with this ???



I'm trying to make a supervision tree example.

I have a Key-Value server with a deliberate error. Looking up the key
'crash' with kv:lookup(crash) should case the server to crash  
with a divide by zero error and the supervisor should restart the server -
instead the supervisor crashes. 

If I do this:

   > simple_sup1:start().
   ...
   > kv:lookup(crash)

The KV server dies as expected, restarts and then the supervisor
itself dies.

Any ideas as to what I've done wrong

/Joe


---- here's simple_sup1.erl ----

-module(simple_sup1).
-behaviour(supervisor).

-export([start/0, init/1]).

start() ->
    supervisor:start_link({local, simple_supervisor},
			  ?MODULE, nil).

init(_) ->
    {ok,{{one_for_one, 5, 1000},
         [
          {server, 
	   {kv, start, []}, 
	   permanent, 5000, worker, [kv]}]}}.

---- here's kv.erl ----


-module(kv).
-behaviour(gen_server).

-export([start/0, stop/0, lookup/1, store/2]).

-export([init/1, handle_call/3, handle_cast/2, 
	 terminate/2]).

start() -> gen_server:start_link({local,kv},kv,arg1,[]).

stop()  -> gen_server:cast(kv, stop).
    
init(arg1) ->
    io:format("Key-Value server starting~n"),
    {ok, dict:new()}.

store(Key, Val) -> 
    gen_server:call(kv, {store, Key, Val}).
    
lookup(Key) -> gen_server:call(kv, {lookup, Key}).

handle_call({store, Key, Val}, From, Dict) ->
    Dict1 = dict:store(Key, Val, Dict),
    {reply, ack, Dict1};
handle_call({lookup, crash}, From, Dict) ->
    1/0;
handle_call({lookup, Key}, From, Dict) ->
    {reply, dict:find(Key, Dict), Dict}.

handle_cast(stop, Dict) -> {stop, normal, Dict}.

terminate(Reason, Dict) ->
    io:format("K-V server terminating~n").










 NOTICE AND DISCLAIMER:
This email (including attachments) is confidential.  If you have received
this email in error please notify the sender immediately and delete this
email from your system without copying or disseminating it or placing any
reliance upon its contents.  We cannot accept liability for any breaches of
confidence arising through use of email.  Any opinions expressed in this
email (including attachments) are those of the author and do not necessarily
reflect our opinions.  We will not accept responsibility for any commitments
made by our employees outside the scope of our business.  We do not warrant
the accuracy or completeness of such information.




More information about the erlang-questions mailing list