Topher Hunt
Topher Hunt

Reputation: 4813

Elixir pry session interrupted because database connection timed out

I was happily following this advice on how to run a debugger inside my Phoenix controller tests:

But after a few seconds this error always appeared:

16:51:08.108 [error] Postgrex.Protocol (#PID<0.250.0>) disconnected: 
** (DBConnection.ConnectionError) owner #PID<0.384.0> timed out because 
it owned the connection for longer than 15000ms

As the message says, the database connection appears to time out at this point and any commands that invoke the database connection will error out with a DBConnection.OwnershipError. How do I tell my database connection not to time out so I can debug my tests in peace?

Upvotes: 6

Views: 1221

Answers (1)

Topher Hunt
Topher Hunt

Reputation: 4813

The Ecto.Adapters.SQL.Sandbox FAQ mentions this issue and explains that you can add the :ownership_timeout setting to your Repo config to specify how long db connections should stay open before timing out. I set mine to 10 minutes (test environment only) so I never have to think about it again:

# config.test.exs

config :rumbl, Rumbl.Repo,
  # ...other settings...
  ownership_timeout: 10 * 60 * 1000 # long timeout so pry sessions don't break

As expected, I can now fool around in pry for 10 minutes before seeing that error.

Upvotes: 7

Related Questions