[erlang-questions] : gen_server question

Raimo Niskanen raimo+erlang-questions@REDACTED
Tue Jan 13 09:36:40 CET 2009


On Mon, Jan 12, 2009 at 09:45:47PM -0800, Howard Yeh wrote:
> > 2009/1/12 Ryan Lepidi <ryeguy1@REDACTED>:
> > Hello,
> >
> > When the server is terminated due to an error occurring in one of its
> > functions, what happens if another process calls one of the server's
> > functions in between the time the server is terminated and the time the
> > supervisor restarts it?
> 
> Hi Ryan,
> 
> 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)

Since gen_server:call nowadays uses erlang:monitor on the
target process, the call should fail if the process is dead
or dies during the call.

Using timeout is generally a bad thing. The monitors should
cover all cases, except the case when the client simply
can not wait any longer. If you use timeout you will have
to be prepared to take care of any garbage late answers 
that may arrive after a timeout.

> 
> >Will the call be queued and executed once the server
> > is back up?
> 
> no
> 
> > Or is there a chance that it could be lost?
> 
> yes

How do you mean lost? It will succeed or fail.

It fails if the server is dead or as soon as
the server dies during the call. If the server
dies during the call there is a chance that the
server received the message, did its thing, but
died before sending the reply, so a failed call
may actually have triggered server side effects.

If the connection breaks up it may take a while
before the remote node is deemed dead, but then
all monitors for processes on the remote node
are triggered.

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

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-questions mailing list