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

Websocket behavior in case of connection issues #678

Closed
gitmalong opened this issue Jan 28, 2022 · 2 comments
Closed

Websocket behavior in case of connection issues #678

gitmalong opened this issue Jan 28, 2022 · 2 comments

Comments

@gitmalong
Copy link

gitmalong commented Jan 28, 2022

Hi!

Does the Websocket client automatically reestablish terminated connections and re-subscribe or is that something I have to implement on top? If the latter is true what would be a good starting point?

I basically want to ensure that the connection is active whenever possible and don't loose any subscriptions.

Thanks for these insights.

@gitmalong gitmalong changed the title Behavior in case of connection issues Websocket behavior in case of connection issues Jan 28, 2022
@niklasad1
Copy link
Member

niklasad1 commented Jan 28, 2022

Hey @gitmalong,

Does the Websocket client automatically reestablish terminated connections and re-subscribe or is that something I have to implement on top?

No, that's something you have to implement yourself. We had some discussions about in the past see #236 for further info.

I basically want to ensure that the connection is active whenever possible and don't loose any subscriptions.

You have to check that yourself by either Client::is_closed or if any call returns Error::RestartNeeded. The subscription itself "should" return None if the connection is closed or subscription is dropped but keep in mind that messages will buffered up to max_notifs_per_subscriptions and those will available even if the connection gets closed. In other words you would have drain all messages to get to that point. Thus, you should be able to ensure that no messages are lost (as long your buffers are large enough) but might be gaps if your connection gets closed.

However, one improvement could be get a callback via future or something to triggers once connection is closed.
You simply have to drop the client and create a new one.

@niklasad1
Copy link
Member

niklasad1 commented Feb 10, 2022

Closing this because I answered your question, re-open again if something wasn't not clear in my answer.

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

2 participants