[erlang-questions] Thoughts on when to use 'infinity' timeouts for gen_server:call and friends

Kenneth Lundin kenneth.lundin@REDACTED
Tue Aug 3 20:35:48 CEST 2010


On Sun, Aug 1, 2010 at 8:43 AM, Andrew Thompson <andrew@REDACTED> wrote:
> So, in trying to scale my application, I run into some cases where the
> default 5 second timeout imposed on all gen_*:call behaviours isn't
> enough and I get cascading timeout failures. I've noticed that most of
> the applications in the OTP distribution use 'infinity' as the timeout
> for all their :calls().
>
> Basically my question is: does anyone have any good rules of thumb for
> when its OK to use a non-standard timeout? Most of my timeouts are
> coming from an external source (waiting on another program to do
> something). Should I just bulletproof certain core modules and say
> "these won't infinite loop, so they can take as long as they need"?
> Should I just do like OTP does and just stick 'infinity' in most
> everywhere?
>
> Thanks,
>
> Andrew
>

The default timeout of 5 seconds is unfortunate but was motivated at
the time when
gen_server was implemented and when the erlang:monitor BIF was not available.
The 5 sec timeout was a compromise in order to save the caller if the
server process
did not exist or died in the middle of handling the call. It was
however impossible to
distinguish between the case where the handling of the call took
longer than the timeout and
when the server crashed during the handling of the call.

Now when we have erlang:monitor it is possible to return to the caller
immediately if
the server does not exist or crashes during handling of the call. The
caller can also
see the difference between a timeout and a crash.

Because of backward compatibility reasons we have not been able to
change the default
timeout for gen_server:call/2 to infinity (it would most probably
break old OTP code as well).

We are however seriously considering to deprecate gen_server:call/2
and recommend all
users to use gen_server:call/3 with infinity timeout for all calls
except some rare occasions where
it really is motivated to have a timeout and the user is prepared to
handle all the potential
problems and raises with that.

If we can find a suitable name we could also introduce new functions
with arity 2 and 3
replacing gen_server:call/2 and 3.

Some suggestions on names are:
call2
call_ex (following the style in the Windows API)
call_nt/2 (nt standing for no timeout, but does that make sense for a
call_nt/3 where the third
argument is the timout in seconds or infinity)

Suggestions on names are welcome.

/Kenneth Erlang/OTP, Ericsson
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
>


More information about the erlang-questions mailing list