Client <pid> timed out because it queued and checked out the connection for longer than

I am regularly getting this error, when importing stuff into the database (videos/photos, seriously rate limited due file copy operation that also happens for every photo).

[error] Postgrex.Protocol (#PID<0.1102.0>) disconnected: ** (DBConnection.ConnectionError) client #PID<0.1291.0> timed out because it queued and checked out the connection for longer than 60000ms

What exactly does this mean?

All of the queries are fast (e.g. ms), approx 5 queries every 30+ seconds, and the query it fails at is random.

In fact, wondering if the problem is that the database is kept idle for too long while it is copying files. Especially large video files. Seems to be less likely to happen for smaller photos which copy faster.

I have increased the timeout to 60 seconds, but still get the issue. But not as frequently as before.

How do I fix? Maybe I do need to set the timeout value to a larger time taken to copy the files. But that just seems weird and strange to me, as the database isn’t doing anything during that time. But maybe that is the problem?

Are you doing file system operations inside of a database transaction?

2 Likes

Good question. Hmmm. No… Oh hang on… Yes I am. I guess that would explain it, and why I only have this problem with this particular code.

Thanks for prodding me, I think this code needs a rewrite now. Wasn’t my intended goal to do everything inside the transaction.

1 Like

How did you increase the timeout ? Thx

Not sure now, but I imagine I altered these config settings: erlang - How to override or disable Postgrex timeout setting: 15 seconds? - Stack Overflow

My current code calls Repo.transaction(..., timeout: :infinity) to get an unlimited transaction.

https://hexdocs.pm/ecto/Ecto.Repo.html#c:transaction/2

1 Like