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

replication connection respects reconnect_backoff option #725

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

DohanKim
Copy link

Replication Connection's {:timeout, :backoff} action does not wait for the time as reconnect_backoff option set.

@@ -487,6 +487,7 @@ defmodule Postgrex.ReplicationConnection do
def handle_event(type, content, state, s)

def handle_event({:timeout, :backoff}, nil, @state, s) do
Process.sleep(s.reconnect_backoff)
Copy link
Member

Choose a reason for hiding this comment

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

The state machine (gen_statem) has an API for sleeping, so that's where it happens. Roughly around line 500:

{:keep_state, s, {{:timeout, :backoff}, s.reconnect_backoff, nil}}

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, I'm not familiar with gen_statem so I'm reading the code now.
Are you referring to this?
https://github.com/erlang/otp/blob/OTP-27.2/lib/stdlib/src/gen_statem.erl#L1188

But anyway when I test after tweaking reconnect_backoff to a huge number,
ReplicationConnection still immediately tries to reconnect without any delay.

@josevalim
Copy link
Member

Thanks @DohanKim, if it is indeed not triggering, we should address it by using the gen_statem APIs.

@whatyouhide can you give us a hand with this one? You have better gen_statem knowledge than I do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants