[erlang-questions] Can gen_fsm be restarted by a supervisor with state data kept?

Tobias Schlager Tobias.Schlager@REDACTED
Wed Jul 31 09:38:18 CEST 2013


What I usually do in the case a server (or FSM) keeps important data in its state is passing in an ets table id owned by the respective supervisor (e.g. created in its init function). In case of an error or exception, the important parts of the state can be saved in the ets table using the terminate callback of the server. When resurrecting, the server can retrieve the data from the table in its init callback function.

However, as mentioned before, restarting with the crash state of a server can be dangerous. You should be extremely careful when selecting the parts of the state to preserve, otherwise you might inject a crash loop which in turn can crash the whole supervision tree.

Regards
Tobias

________________________________________
Von: erlang-questions-bounces@REDACTED [erlang-questions-bounces@REDACTED]" im Auftrag von "Bengt Kleberg [bengt.kleberg@REDACTED]
Gesendet: Mittwoch, 31. Juli 2013 09:20
Cc: erlang-questions
Betreff: Re: [erlang-questions] Can gen_fsm be restarted by a supervisor with state data kept?

Greetings,

The FSM has crashed. Is it really a good idea to start it with the same
state data?


bengt

On Wed, 2013-07-31 at 14:41 +0800, Barco You wrote:
> Dear All,
>
>
> I have a gen_fsm instance which is supervised by a supervisor. The
> gen_fsm instance sometimes crashed and then restarted by the
> supervisor, but the state data was reinitialized. How can I restart
> this instance with the state data it has at crash point?
>
>
> Thank you.
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

_______________________________________________
erlang-questions mailing list
erlang-questions@REDACTED
http://erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list