diff --git a/lib/postgrex/protocol.ex b/lib/postgrex/protocol.ex index 71ab59c9..fd08ff2b 100644 --- a/lib/postgrex/protocol.ex +++ b/lib/postgrex/protocol.ex @@ -68,6 +68,9 @@ defmodule Postgrex.Protocol do {:ok, state} | {:error, Postgrex.Error.t() | %DBConnection.ConnectionError{}} def connect(opts) do + # Trap exits so that DBConnection calls `disconnect` on unexpected shutdowns + Process.flag(:trap_exit, true) + endpoints = endpoints(opts) timeout = opts[:timeout] || @timeout