<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><span style="font-family:Arial,Helvetica,sans-serif">On Thu, Sep 19, 2019 at 7:33 PM Roger Lipscombe <<a href="mailto:roger@differentpla.net">roger@differentpla.net</a>> wrote:</span><br></div></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
Is there a way that I can instrument gen_server so that it will log<br>
something if it takes too long to return from a callback? That is: my<br>
handle_call is timing out because, presumably, there's another<br>
handle_call (or handle_info, etc.) that's blocking. I'd like *that* to<br>
be logged if it takes longer than, say, 200 milliseconds to return.<br>
<br></blockquote><div><br></div><div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">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.</div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif"><br></div><div class="gmail_default" style="font-family:arial,helvetica,sans-serif">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.</div><br></div></div></div>