How to capture timeout error from Repo.all()

I am reasonably new to elixir, and am trying to capture an error that stems from a query timing out. This code for this query is as follows:

Repo.all(query, [timeout: 5000])

with the “query” obviously being some form of Ecto.Query. This works great, I am just trying to handle if that query times out. If that query times out, it throws something similar to:

[error] MyXQL.Connection (#PID<0.676.0>) disconnected: ** (DBConnection.ConnectionError) client #PID<0.1508.0> timed out because it queued and checked out the connection for longer than 5000ms

Client #PID<0.1508.0> is still using a connection from owner at location:

    (myxql 0.2.10) lib/myxql/client.ex:171: MyXQL.Client.recv_packets/4
    ... (stacktrace)

The connection itself was checked out by #PID<0.1508.0> at location:

    (ecto_sql 3.2.2) lib/ecto/adapters/sql.ex:570: Ecto.Adapters.SQL.execute!/4
   ... (stacktrace)

The trouble is, I am trying to wrap the Repo.all(query, [timeout: 5000]) in a try/rescue to catch when this error occurs, but it doesn’t appear to work when I am in tests. Is there a better way to handle this? There is no specific exception thrown, it is just labeled as an “error” as seen from the logs I wrote above.

Any help is greatly appreciated, let me know if I need to be more clear on anything!
Thanks! :smiley:

@ahav did you manage to solve it? Im facing the same situation here