why catch gen_server; MOD:handle_call?

Samuel Rivas <>
Thu Jul 8 15:37:47 CEST 2004


Ulf Wiger wrote:
> I would suggest that terminate/2 be used only to do 
> 'obvious' cleanup, i.e. the stuff you'll want to do 
> before a normal shutdown. This could involve explicitly
> closing files that are open, unloading mibs, etc.
> 
> Cleaning up possible inconsistencies should be done 
> after restart, even though telling the difference between
> a normal start and a restart after error might be tricky.

  I think this problem should be addressed to the supervisor. You would
be able to easily handle different restarts for normal and after-error
restarts if supervisor could pass different arguments to start_link
depending on the reason of the restart.

  I couldn't figure out how to do this with the actual implementation, so
I have to do tricky (and ugly) things in the gen_servers. With the
approach above you can carry out a smart separation of error-handling
code and normal-code in the gen_server init function and leave
the terminate function free of dreadful error-clean-up code.

  I recall reading something about a new supervisor implementation in
this list some time ago, but I can't find the link ...
-- 
	Samuel



More information about the erlang-questions mailing list