[erlang-questions] gen_server and the run-time errors

Robert Virding <>
Wed Dec 8 10:24:08 CET 2010


IIRC it is so, terminate/1 is not called if there is an error in init/1. I remember having read about it somewhere but can't find it now. The closest I could come up with is in http://erlang.org/doc/man/gen_server.html#start_link-3 where it says:

"If Module:init/1 fails with Reason, the function returns {error,Reason}. If Module:init/1 returns {stop,Reason} or ignore, the process is terminated and the function returns {error,Reason} or ignore, respectively."

Also the documentation explicitly mentions how to return a value from other callback functions which causes the server to call terminate/1 and then terminate, but no mention of terminate is made in the docs for init/1.

The logic is I suppose that if you haven't completed initialisation then there is nothing to clean-up after.

Robert

----- "Gilberio Carmenates García" <> wrote:

> Hi! Info,
> 
> The terminate function isn't called possibility because the gen_server
> never
> started,
> Your problem could be I'm close sure because the init() need to be
> ended
> with a {ok, Pid}, Pid could be self(). If you end the init() function
> with
> other thing, the same error you saw is threw.
> 
> 
> Good Example:
> 
> init(Args)->
> 	process_flag(trap_exit,true),
> 	evo_db_module:start(Args),
> 	{ok, self()}.
> 
> 
> Bad Example:
> 
> init(Args)->
> 	process_flag(trap_exit,true),
> 	evo_db_module:start(Args),
> 	some_fun_that_not_returns_ok_pid().
> 
> 	
> =INFO REPORT==== 7-Dec-2010::20:37:58 ===
>     application: evo
>     exited: {shutdown,{evo,start,[normal,[{...}]]}}
>     type: temporary
> 
> Best,
> 
> Ivan.
> 
> 
> -----Mensaje original-----
> De:  [mailto:]
> En
> nombre de info
> Enviado el: Martes, 07 de Diciembre de 2010 14:50
> Para: erlang-questions
> Asunto: [erlang-questions] gen_server and the run-time errors
> 
> Hello,
> I have a run-time error in the init part of a gen_server.
> - Init begin by process_flag(trap_exit,true)
> - gen_server is part of a supervision tree
> I try to print the reason in the terminate module but it seems to
> exit
> elsewhere.
> - why terminate is not called ?
> The application stops with shutdown as reason. 
> - How and where to catch the run-time error ?
> 
> J-Ph. Constantin
> ITS3 Genhve
> www.its3.ch
> 
> 
> =======================================================================
> Este mensaje ha sido enviado mediante el servicio de correo
> electrónico que ofrece la Federación de Radioaficionados de Cuba a sus
> miembros para respaldar el cumplimiento de los objetivos de la
> organización y su política informativa. La persona que envía este
> correo asume el compromiso de  usar el servicio a tales fines y
> cumplir con las regulaciones establecidas.
> 
> 
> 
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:


More information about the erlang-questions mailing list