[erlang-questions] gen_server:call vs. restart

Jack Orenstein <>
Wed Oct 31 03:35:18 CET 2007


Suppose I have the following modules:

- A gen_server.

- A supervisor that restarts the gen_server when necessary.

- A test that invokes functions of the gen_server with  
gen_server:call (using a global name, not a PID).

The test keeps calling gen_server functions. A separate process in  
the test module occasionally causes the gen_server to crash.  After  
the gen_server crash, and before the supervisor restarts it, a  
gen_server:call will fail, throwing a noproc exception. What is the  
right way to bulletproof the test program against this occurrence?

I could catch the noproc, wait a short while and try the call again.  
This doesn't seem very elegant, and it would be quite a pain to have  
to do this on each gen_server:call invocation.

I could add another supervisor, to restart the main process that was  
killed by the noproc exception, but this would lose any state that  
the process had. Not a problem for my test, but this could be a  
problem in practice.

Is there a standard approach to dealing with this problem?

Jack Orenstein




More information about the erlang-questions mailing list