Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elixir pry session interrupted because database connection timed out

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

  • require IEx in the target file
  • add IEx.pry to the desired line
  • run the tests inside IEx: iex -S mix test --trace

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?

like image 420
Topher Hunt Avatar asked Nov 29 '16 23:11

Topher Hunt


1 Answers

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.

like image 61
Topher Hunt Avatar answered Oct 15 '22 00:10

Topher Hunt