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

add timeout to websocket connection and socket heartbeat #86

Merged
merged 4 commits into from
Aug 13, 2024

Conversation

Neelansh-ns
Copy link
Contributor

Add timeout to websocket connection and send socket heartbeat, else in case of no internet, await _ws!.ready is stuck indefinitely. This causes the socket not to try reconnecting while the internet is not present.

A similar case would happen in the previous versions of the library when await _ws!.ready was not added. It gets stuck indefinitely when sending a socket heartbeat.

@RodolfoSilva
Copy link

Nice job @Neelansh-ns

I think a better solution would be to expose a method like: reconnect(), to allow the application to handle when the socket should or should not try the connection again. This allows the application to use the connection-plus plugin to check when the connection changes and then try to reconnect.

What do you think @Neelansh-ns @matehat

@Neelansh-ns
Copy link
Contributor Author

I think a better solution would be to expose a method like: reconnect(), to allow the application to handle when the socket should or should not try the connection again. This allows the application to use the connection-plus plugin to check when the connection changes and then try to reconnect.

The issue this PR would solve is that it is adding a timeout to the ready future await _ws!.ready and similarly for sending the heartbeat. If this won't we there it takes around close 120 to 180 seconds to get a WebSocketException with the error message OS Error Time Out .

On receiving such an error, the _onSocketError callback is triggered which in turn calls _onSocketClosed which tries to reconnect as _shouldReconnect is true.

So the reconnect functionality is there, but it takes a sufficient amount of time awaiting the futures. Hence this PR adds a timeout for that.

I'll try to open a separate PR for the reconnect, which would require some refactoring.

@Neelansh-ns
Copy link
Contributor Author

@RodolfoSilva did you get a chance to check this?

Copy link
Member

@matehat matehat left a comment

Choose a reason for hiding this comment

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

💯

@matehat
Copy link
Member

matehat commented Aug 13, 2024

Nice job @Neelansh-ns

I think a better solution would be to expose a method like: reconnect(), to allow the application to handle when the socket should or should not try the connection again. This allows the application to use the connection-plus plugin to check when the connection changes and then try to reconnect.

What do you think @Neelansh-ns @matehat

As mentioned by @Neelansh-ns, I think this issue is orthogonal to the need for a reconnect() method, which I think is also a good idea!

@matehat matehat merged commit 25fa1da into braverhealth:master Aug 13, 2024
1 check passed
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.

3 participants