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

handle disconnect backoff #111

Open
BrendanBall opened this issue Jun 3, 2022 · 0 comments
Open

handle disconnect backoff #111

BrendanBall opened this issue Jun 3, 2022 · 0 comments

Comments

@BrendanBall
Copy link

Websockex currently supports infinite reconnect to handle intermittent network failures, however it is still quite limiting.
Currently it only supports attempting to reconnect directly after disconnecting with:

      def handle_disconnect(status, state) do
        {:reconnect, state}
      end

However this means that it spams reconnect.
You could theoretically put in a Process.sleep to handle some kind of backoff, however I don't think that's a good solution since it's a blocking operation, so backoff is better implemented with Process.send_after.

I believe Ecto has implemented this quite well for DB connections, and has created a reusable library which defines a behaviour for implementing connection processes (see https://hexdocs.pm/connection/Connection.html).
Unfortunately it does this by implementing its own special process, which WebSockex also does, so the 2 can't be tightly integrated.
I'm currently looking at using the Connection library on top of WebSockex to solve this, which I believe should work, however given that WebSockex almost already supports this and it's clearly a common feature (since we want our applications to be fault tolerant), I want to find out whether you're interested in having reconnection logic in WebSockex improved so that it's as simple as specifying some backoff parameters for users of WebSockex. I'm currently considering just copying the design of Connection to WebSockex since I don't think it's that much code and WebSockex has its own reasons for implementing a custom special process (although it would've been easy to integrate this if it was just using a GenServer).

What's your opinion? Would you accept a PR for this?

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

No branches or pull requests

1 participant