[erlang-questions] gen_server question

Hynek Vychodil <>
Tue Jan 13 15:05:20 CET 2009


It's very well written. Anyway for one who can't found it in code, answer
is: In case when server doesn't exists gen_server:call function exits with
{noproc, {gen_server, call, [Name, Request, Timeout]}}.

On Tue, Jan 13, 2009 at 2:44 PM, Christian <> wrote:

> > correct me if i am wrong:
> >
> > messages are dropped if the receiving process is dead.
> >
> > with gen_server, if you use synchronized call, you can specify a timeout
> value
> >
> > gen_server:call(ServerRef, Request, Timeout)
> >
> > "The call may fail for several reasons, including timeout and the
> > called gen_server dying before or during the call."
> >
> > I think you get either a badarg (pid doesn't exist (as it's dead)) or
> > timeout (if the process died after message had been sent)
>
> Every time I want to remind myself on how this works i look at the
> do_call/4 function in
> lib/stdlib/src/gen.erl, it is the one that implement the
> gen_server:call currently.
>
> (Disclaimer, there can of course be undocumented features in the code
> that one should not rely on. But it is so much easier to understand
> code than english that describes code. :)
>
> What you learn is that gen_server:call will create a monitor on the
> server for the duration of the call. So it will detect immediately if
> the server has crashed, or if it crashes while it is waiting on a
> reply. Another fun trivia is that the monitor reference is used as a
> unique id to identify the correct request/response from the
> gen_server.
>
> Timeouts are really just relevant for gen_servers that are so bogged
> down that they cant get around to process your request and reply to it
> in time. (Also some code there for if its a node that doesnt support
> monitoring of processes). The gen_server will not notice that the
> caller have timed out, so it will process the request when it gets to
> it, unless it has crashed for other reasons by then.
> _______________________________________________
> erlang-questions mailing list
> 
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



-- 
--Hynek (Pichi) Vychodil

Analyze your data in minutes. Share your insights instantly. Thrill your
boss.  Be a data hero!
Try Good Data now for free: www.gooddata.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090113/3537b2fb/attachment.html>


More information about the erlang-questions mailing list