[erlang-questions] Diagnosing gen_server call timeouts

Jesper Louis Andersen jesper.louis.andersen@REDACTED
Thu Sep 19 20:56:03 CEST 2019


On Thu, Sep 19, 2019 at 7:33 PM Roger Lipscombe <roger@REDACTED>
wrote:

>
> Is there a way that I can instrument gen_server so that it will log
> something if it takes too long to return from a callback? That is: my
> handle_call is timing out because, presumably, there's another
> handle_call (or handle_info, etc.) that's blocking. I'd like *that* to
> be logged if it takes longer than, say, 200 milliseconds to return.
>
>
The calling process is terminated by means of an exit signal, by calling
`exit(timeout)`. You can capture this with an exception handler and then
use erlang:process_info/2 to capture the gen_servers state when this
happens (or you can try sys:get_state if it does return at some point).
Essentially you turn your calling process into the logger. This works
insofar there are relatively few of these errors, and it can explain what
the called process is sitting and doing while this happens.

One thing to be aware of is that if you capture the timeout, then the real
reply message might arrive late in your mailbox. You will have to handle
this accordingly, should you opt to make the process continue.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20190919/fc3ce4cf/attachment.htm>


More information about the erlang-questions mailing list