[erlang-questions] The Danger of gen:server timeout

Jachym Holecek freza@REDACTED
Fri Jun 2 14:25:14 CEST 2017

# Jesper Louis Andersen 2017-06-02:
> Here is the crux of what you are toying with: Erlang has two kinds of
> timeouts: idle timeouts and point-in-time timeouts. The timeouts you can
> set in a gen_server are idle timeouts, so they are implemented basically as
> receive
>   ...
> after Timeout ->
>   ...
> end

They may happen to be implemented that way in gen_server, but it is debatable
whether this is intentional (might have been purely for simplicity) and
whether this is correct as far as expectations go -- system messages are
not seen by the user code running the gen_server process (they are handled
under the hood), so as far as user logic is concerned the server had been
idle despite these under-the-hood messages perhaps flowing through.

Not that this has ever been an issue for me personally, and as you indicate
it's extremely easy to work around explicitely... But I do recall implementing
idle timeouts with erlang:start_timer/X without resetting the timer on
system messages in a custom behaviour module on at least one occasion,
and I recall thinking implemention in gen_server / gen_fsm (which I used
as reference) was a bit suspicious, although in a harmless way.

So there's that.

	-- Jachym

More information about the erlang-questions mailing list