Recommended way to crash gen_server

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Recommended way to crash gen_server

Albin Stigö-2
Hello,

I have a gen_server communicating with a port program I wrote in C.

If I receive any unexpected data (or timeout) from the port I want to
crash the gen_server.

Regarding crashing, Is the recommended approach to return {stop,
Reason} or should I exit(Reason) or maybe even throw(Reason).

I want my supervisor to try to restart the gen_server according to the
strategy/intensity I've chosen.


--Albin
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Recommended way to crash gen_server

Fred Hebert-2
On 07/08, Albin Stigö wrote:
>Regarding crashing, Is the recommended approach to return {stop,
>Reason} or should I exit(Reason) or maybe even throw(Reason).

I would go with {stop, Reason, State}, allowing the gen_server to clean
up what it may need to (if at all). The Reason returned will be used by
the behaviour to 'exit' the process all the same.

Do note that the following reasons will *NOT* be seen as abnormal
terminations, so a transient supervisor will not restart them:

- normal
- shutdown
- {shutdown, Term}

although the latter may be useful to document the type of normal
expected exit that happened.
_______________________________________________
erlang-questions mailing list
[hidden email]
http://erlang.org/mailman/listinfo/erlang-questions
Loading...