From 920261518f96c6d83918d4a6d2d61a097126d152 Mon Sep 17 00:00:00 2001 From: Yuri Artemev Date: Tue, 12 Nov 2024 12:22:18 +0300 Subject: [PATCH] call disconnect on protocol when reconnecting in simple connection --- lib/postgrex/simple_connection.ex | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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])