I have an erlang module with behaviour gen_server.
Now, I have:
init(_Args) ->
erlang:send_after(?PROCESS_STATE_INTERVAL,self(),processState),
{ok, []}.
and
handle_info(processState, _State)->
{ok, NewState} = gen_server:call(self(), {updateLvls}), %works fine, tested
timer:send_after(?PROCESS_STATE_INTERVAL,self(),processState),
{noreply, NewState}.
When I start it with something like {ok, Test}=gen_server:start_link({local,challenge_manager},challenge_manager,[],[]). after a few seconds I get ** exception error: {timeout,{gen_server,call,[<0.329.0>,{updateLvls}]}}
Am I doing something wrong??
You cannot call your own
gen_serverfrom within itself. That will result in a dead lock (which is what you see). The server process is busy handling your first request (since you haven’t returned yet) and will queue the second request (which is made from the handling of the first), thus dead lock.To solve this, either create a library function which both
handle_callandhandle_infouses, or take a look at thereply/2function which will let you do asynchronous replies (if you return{noreply, ...}from yourhandle_callfunction).