Postgrex connection closed in mix task

So I have this mix task that lasts for more than 1 hour.

When I run it, I get a (DBConnection.ConnectionError) client #PID<0.93.0> timed out because it queued and checked out the connection for longer than 60_000 seconds.

I read, I can increase the timeout, though I can’t succeed in doing this only for the current mix task. I tried to set environment variables in my mix task, but apparently values are already initialized before the task’s run(args) method is called.

  • So I can I make a timeout task-specific?

But another solution would be to close the connection during the script, wouldn’t it?
It surprises me because in this script, I’d call indenpendant updates like:

Repo.get(%struct{}, id) |> Struct.changeset(%{tada: true}) |> Repo.update()

I would expect this query to be commited in the DB, hence the connection can be closed after the Repo.update() is called, but it apparently isn’t…

  • Should I manually close and commit the query? Can I do this? Or am I leaving a connection open without being aware of it?

Thanks for support

As I understand the way how DB connections get pooled and checked out, the snippet should checkout a connection, do the SELECT, then chack it back into the pool, after that it modifies the changeset, then it checks out a new connection from the pool, does the UPDATE, then hands the connection back to the pool.

So you have probably some single query (or multi) which does take long enough to time out.

Hard to say wihtout knowing more about your task and especially without knowing anything about the query.