Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

call disconnect on protocol when reconnecting in simple connection #717

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/postgrex/simple_connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link

@grzuy grzuy Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thanks for this fix.

Could it be though that this needs to consider a case in which protocol is nil?

We got this error in production with the latest postgrex 0.19.3

image

Note cancel_request(nil) call.

Thanks!

Copy link

@grzuy grzuy Nov 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the logs from when this error happened...

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed to main.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @josevalim 🙏

{: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])
Expand Down
Loading