Mysterious production bug "Erlang error message: :timeout_value, from :gen_server.loop/7"

Hey all. I’m working on a mysterious production bug that’s got me a bit stuck, and I’m curious if anyone has experienced something like this before and could give me any suggestions as to what I might be missing.

I’m getting this Erlang error message in my logs Erlang error: :timeout_value, from :gen_server.loop/7

It’s coming from a GenServer process that is running a bunch of application code in handle_cast/2. The logs show all the application code running successfully, but this error is the last thing I see in the logs before the process crashes. It’s mysterious because in my understanding a cast does not employ a timeout. I looked at the OTP source for the line cited in the stacktrace, but my limited understanding of that codebase isn’t getting me anywhere. It seems to just reference where the issue is being logged and not where it’s coming from, but nonetheless.

This is the offending line:

Debug1 = sys:handle_debug(Debug, fun print_event/3, Name, Msg),

In this function:

%%% ---------------------------------------------------
%%% The MAIN loop.
%%% ---------------------------------------------------

loop(Parent, Name, State, Mod, {continue, Continue} = Msg, HibernateAfterTimeout, Debug) ->
    Reply = try_dispatch(Mod, handle_continue, Continue, State),
    case Debug of
	[] ->
	    handle_common_reply(Reply, Parent, Name, undefined, Msg, Mod,
				HibernateAfterTimeout, State);
	_ ->
	    Debug1 = sys:handle_debug(Debug, fun print_event/3, Name, Msg),
	    handle_common_reply(Reply, Parent, Name, undefined, Msg, Mod,
				HibernateAfterTimeout, State, Debug1)
    end;

1 Like

handle_cast/2 might return {:noreply, new_state, timeout} where timeout might be of some “bad value” in your case.

5 Likes

Thanks for the suggestion, but not the case here.

@idi527 is mostly likely correct. Check your returns from the GenServer callbacks. Somewhere you are returning a value in the timeout field. It is not only handle_cast but any callback.

7 Likes

Thanks to both of you. It wasn’t the return of handle-cast/2, but I found a catch-all for handle_info/2 that was mistaken returning a triple with the process state struct as the 3rd element.

I had this when using handle_continue in my code. I had not updated my erlang version. Like @idi527 said, when you hit this, it’s almost def something to do with your returns from the calls.

1 Like