You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Does the library support reconnect? When the server goes down, it'd be nice if the websocket client tried to reconnect indefinitely (or have some sort of backoff strategy).
It's implemented through handle_disconnect. I don't think it will try to connect indefinitely though. I'll look at the overhead of doing that.
It shouldn't be a problem, but I may suggest to wrap the WebSockex process in a GenServer then monitor the process and then try the reconnecting from there. You would have a lot more control on the backoff strategy that way as well.
@Azolo thanks for the information! I'm still new to elixir so please forgive me for my ignorance. I have a couple more questions:
I'm still not quite sure I understand how returning {:reconnect, state} from handle_disconnect will reconnect. When I do, instead of looping, it raises and exits the process.
I noticed that there are quite a few places that have the process exit (from a raise). Given I've wrapped the websocket client in my own custom GenServer for reconnecting, how do I handle the exiting of the process? I see:
Then it's raising a WebSockex.ConnError because you couldn't establish a connection and error'd with :econnrefused. It expects the server to be there when you try to reconnect, when it's not it does a nice 💥.
An alternative workaround to wrapping the WebSockex process would be to poll the endpoint in the handle_disconnect callback until it was available again then returning {:reconnect, state}.
Activity
Azolo commentedon May 9, 2017
It's implemented through
handle_disconnect. I don't think it will try to connect indefinitely though. I'll look at the overhead of doing that.It shouldn't be a problem, but I may suggest to wrap the WebSockex process in a GenServer then monitor the process and then try the reconnecting from there. You would have a lot more control on the backoff strategy that way as well.
[-]Reconnect[/-][+]Try to reconnect indefinitely[/+]ericTsiliacos commentedon May 9, 2017
@Azolo thanks for the information! I'm still new to elixir so please forgive me for my ignorance. I have a couple more questions:
Azolo commentedon May 9, 2017
@ericTsiliacos I did this off the top off my head and didn't test it at all, but I think this gist should do what you're looking for.
https://gist.github.com/Azolo/75f6a304b9a835d54c25a8ab543630a0
To answer your question about returning
{:reconnect, state}, what that is doing is trying to reconnect once.Then it's raising a
WebSockex.ConnErrorbecause you couldn't establish a connection and error'd with:econnrefused. It expects the server to be there when you try to reconnect, when it's not it does a nice 💥.An alternative workaround to wrapping the WebSockex process would be to poll the endpoint in the
handle_disconnectcallback until it was available again then returning{:reconnect, state}.Azolo commentedon May 16, 2017
This was fixed by #7, you'll have to implement another callback but the means are now baked into WebSockex. 😸