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

Handling disconnection #249

Open
pawanjay176 opened this issue Aug 28, 2019 · 5 comments
Open

Handling disconnection #249

pawanjay176 opened this issue Aug 28, 2019 · 5 comments

Comments

@pawanjay176
Copy link

Currently, if I disconnect my websocket service while a request is in progress, the request just hangs. Is there any way I can detect disconnection from an endpoint and try to reconnect?

@tomusdrw
Copy link
Owner

Unfortunately not yet. The ws transport should be handling reconnects on it's own, but it's not implemented. PRs welcome! :)

@pawanjay176
Copy link
Author

Could you give me some basic pointers as to how to go about doing that?

My idea is to send a periodic OwnedMessage::Ping message in the writer future within with_event_loop function and if we don't get a response within some timeout, then call the with_event_loop function recursively to reconnect. Does this approach make sense?

@tomusdrw
Copy link
Owner

tomusdrw commented Sep 2, 2019

Yeah, that makes perfect sense. Make sure to make Ping interval configurable. I was actually sure that websocket crate is handling low-level WS pings on it's own, but apparently it's not.

@ngugcx
Copy link

ngugcx commented Jul 23, 2021

Could you give me some basic pointers as to how to go about doing that?

My idea is to send a periodic OwnedMessage::Ping message in the writer future within with_event_loop function and if we don't get a response within some timeout, then call the with_event_loop function recursively to reconnect. Does this approach make sense?

Does this idea still make sense? @tomusdrw. Let me see if I can help.
Without timeout and reconnection, it makes this wonderful crate useless in long-run jobs.

@tomusdrw
Copy link
Owner

Does this idea still make sense?

Yes, I believe so! The ideal implementation is not going to be trivial though, but I think having at least some basic disconnection/timeout detection mechanism will be better than nothing.

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

No branches or pull requests

3 participants