diff --git a/lib/postgrex/simple_connection.ex b/lib/postgrex/simple_connection.ex index abb16d93..48fec234 100644 --- a/lib/postgrex/simple_connection.ex +++ b/lib/postgrex/simple_connection.ex @@ -337,7 +337,12 @@ defmodule Postgrex.SimpleConnection do @impl :gen_statem def handle_event(type, content, statem_state, state) - def handle_event(:internal, {:connect, _}, @state, %{state: {mod, mod_state}} = state) do + def handle_event(:internal, {:connect, :reconnect}, @state, %{protocol: protocol} = state) do + Protocol.disconnect(:reconnect, protocol) + {:keep_state, %{state | protocol: nil}, {:next_event, :internal, {:connect, :init}}} + end + + def handle_event(:internal, {:connect, :init}, @state, %{state: {mod, mod_state}} = state) do opts = case Keyword.get(opts(mod), :configure) do {module, fun, args} -> apply(module, fun, [opts(mod) | args])