[erlang-questions] gen_statem 20.3 init/1 - {next_event, internal, initial_event}

Raimo Niskanen raimo+erlang-questions@REDACTED
Thu Mar 15 14:51:41 CET 2018


I am sorry i fubmled when optimizing gen_statem.  That typo is mine,
besides the erroneous actions list handling from init/1.

This diff should fix the problems:

diff --git a/lib/stdlib/src/gen_statem.erl b/lib/stdlib/src/gen_statem.erl
index b1d99e2..eb0d6bd 100644
--- a/lib/stdlib/src/gen_statem.erl
+++ b/lib/stdlib/src/gen_statem.erl
@@ -677,9 +677,9 @@ enter(Module, Opts, State, Data, Server, Actions,
Parent) ->
     NewDebug = ?sys_debug(Debug, {Name,State}, {enter,Event,State}),
     case call_callback_mode(S) of
        #state{} = NewS ->
-           loop_event_actions(
+           loop_event_actions_list(
              Parent, NewDebug, NewS,
-             Events, Event, State, Data, #trans_opts{},
+             Events, Event, State, Data, false,
               NewActions, CallEnter);
        [Class,Reason,Stacktrace] ->
            terminate(
@@ -1295,7 +1295,7 @@ parse_actions_next_event(
                 next_events_r = [{Type,Content}|NextEventsR]});
         _ ->
             [error,
-             {bad_action_from_state_function,{next_events,Type,Content}},
+             {bad_action_from_state_function,{next_event,Type,Content}},
              ?STACKTRACE(),
              ?not_sys_debug]
     end;
@@ -1312,7 +1312,7 @@ parse_actions_next_event(
                 next_events_r = [{Type,Content}|NextEventsR]});
         _ ->
             [error,
-             {bad_action_from_state_function,{next_events,Type,Content}},
+             {bad_action_from_state_function,{next_event,Type,Content}},
              ?STACKTRACE(),
              Debug]
     end.



That, running it through our daily builds, and apparently writing a
writing a missing test case. ;-)

I am at the San Francisco Code Beam event right now so a patch will have to
wait to next week..

Sorry about this!
/ Raimo Niskanen



On Thu, Mar 15, 2018 at 12:32:04PM +0000, Guilherme Andrade wrote:
> Crash log mentions 'next_events' (rather than 'next_event'.) Perhaps you
> have a typo somewhere? But if that's the case, then it's weird that 20.2.x
> doesn't complaint about it as well.
> 
> On 15 March 2018 at 11:23, Peter Morgan <peter.james.morgan@REDACTED>
> wrote:
> 
> > Hello -
> >
> > I am sure I am doing something daft. I picked up 20.3 this morning and
> > have some gen_statem code that previously worked in 20.2.4:
> >
> > -module(ex1).
> >
> > -export([callback_mode/0]).
> > -export([handle_event/4]).
> > -export([init/1]).
> > -export([start/0]).
> >
> > start() ->
> >     gen_statem:start({local, ?MODULE}, ?MODULE, [], []).
> >
> > init([]) ->
> >     {ok,
> >      initial_state,
> >      initial_data,
> >      {next_event, internal, initial_event}}.
> >
> > callback_mode() ->
> >     handle_event_function.
> >
> > handle_event(Type, Event, State, Data) ->
> >     error_logger:info_report([{type, Type},
> >                               {event, Event},
> >                               {state, State},
> >                               {data, Data}]),
> >     keep_state_and_data.
> >
> >
> >
> >
> > brew switch erlang 20.2.4
> >
> > Erlang/OTP 20 [erts-9.2.1] [source] [64-bit] [smp:4:4] [ds:4:4:10]
> > [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
> >
> > Eshell V9.2.1  (abort with ^G)
> > 1> ex1:start().
> > {ok,<0.62.0>}
> >
> > =INFO REPORT==== 15-Mar-2018::12:13:29 ===
> >     type: internal
> >     event: initial_event
> >     state: initial_state
> >     data: initial_data
> >
> >
> >
> > brew switch erlang 20.3
> > Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:4:4] [ds:4:4:10]
> > [async-threads:10] [hipe] [kernel-poll:false] [dtrace]
> >
> > Eshell V9.3  (abort with ^G)
> > 1> c(ex1).
> > {ok,ex1}
> > 2> ex1:start().
> > {ok,<0.67.0>}
> > 3>
> > =ERROR REPORT==== 15-Mar-2018::12:15:02 ===
> > ** State machine ex1 terminating
> > ** Last event = {internal,init_state}
> > ** When server state  = {initial_state,initial_data}
> > ** Reason for termination = error:{bad_action_from_state_function,
> >                                       {next_events,internal,
> > initial_event}}
> > ** Callback mode = handle_event_function
> > ** Stacktrace =
> > **  [{gen_statem,parse_actions_next_event,7,
> >                  [{file,"gen_statem.erl"},{line,1299}]},
> >      {gen_statem,loop_event_actions_list,10,
> >                  [{file,"gen_statem.erl"},{line,1194}]},
> >      {proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,247}]}]
> >
> >
> > The docs seem to indicate that next_event remains valid on init/1 -
> > http://erlang.org/doc/man/gen_statem.html#type-init_result.
> >
> > Thanks
> > Peter.
> >
> >
> > _______________________________________________
> > erlang-questions mailing list
> > erlang-questions@REDACTED
> > http://erlang.org/mailman/listinfo/erlang-questions
> >
> >
> 
> 
> -- 
> Guilherme

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


-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list