We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Catching GenServer.call/3 timeout exits
almirsarajcic
0 comments
Copy link
GenServer.call/3 does not return {:error, :timeout} when the server misses its deadline. It exits the caller instead.
def fetch(server) do
try do
{:ok, GenServer.call(server, :fetch, 100)}
catch
:exit, {:timeout, {GenServer, :call, _}} ->
{:error, :timeout}
end
end
A bare :timeout catch never matches because the exit reason includes the call details.
Catch that full shape only when a timeout is an expected result in your client API. If the server replies after the caller continues, that late reply can still arrive in the caller’s mailbox.
copied to clipboard