[erlang-bugs] gen_server timeout disturbed by system messages

Dániel Szoboszlay dszoboszlay@REDACTED
Wed Oct 1 14:14:59 CEST 2014


Hi,

When a gen_server (or gen_fsm, which is very similar in this aspect) is waiting for a message with a finite timeout but receives a system message, it will return to the message loop with the original timeout value. I think this is an incorrect behaviour.

Let’s say I set the timeout to 60 seconds, and 20 seconds later a system message arrives. After handling it the gen_server loop will wait a full 60 seconds until I receive the timeout - a total of 80 seconds instead of 60. Even worse, if a monitoring tool (like observer) keeps polling the server for its state I may never ever get a timeout.

The docs say:

> If an integer timeout value is provided, a timeout will occur unless a request or a message is received within Timeout milliseconds.


I’m not sure whether a “message" in this text should mean a "system message" too, but I think system messages are not very well known and for me the docs read my gen_server code will get back the control via a handle_call, handle_cast or handle_info callback within the timeout specified. Loosing control for ever is definitely not something I would be prepared for when setting a timeout.

So I believe the gen_server code shall record the time when the wait started, and after processing a system message deduce the elapsed time from the original timeout. This way the timeout would occur when it should (unless the process receives system messages faster than it could handle them and can never clear its message queue of course).

Let me know whether you agree with me on the expected behaviour - if you do, I can write a patch and submit a PR, but I don’t want to waste my time working on a non-issue.

Thanks & Regards,
Daniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20141001/e2fbda5d/attachment.htm>


More information about the erlang-bugs mailing list