Elixir-pry session terminates because database connection time has ended

I enjoyed following this tip on how to run the pry debugger inside my Phoenix controller tests:

  • require IEx in the target file
  • add IEx.pry to the desired line
  • run 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 stated in the message, the connection to the database appears at that moment, and any commands that cause the connection to the database will fail using DBConnection.OwnershipError . How do I report a database connection to a timeout so that I can safely debug my tests?

+5
source share
1 answer

The Ecto.Adapters.SQL.Sandbox FAQ mentions this problem and explains that you can add the :ownership_timeout parameter to your Repo configuration to indicate how long db connections should remain open until time runs out. I set minus 10 minutes (test environment only), so I no longer need to think about it:

 # 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 trick into pry for 10 minutes before seeing this error.

+3
source

Source: https://habr.com/ru/post/1260554/


All Articles