-
Notifications
You must be signed in to change notification settings - Fork 94
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
Async Client Doesn't Handle Internet Disconnection #555
Comments
i'm not sure this is the right solution, but one idea would be to start a second it would be something like this: class WebsocketBase():
def __init__(self, timeout):
....
self.timeout = timeout
async def _ping_sender(self):
while self.is_open():
async with asyncio.TaskGroup() as tg:
x = tg.create_task(self._do_request_impl(<<<SEND PING>>>))
y = tg.create_task(asyncio.sleep(self.timeout))
# now either both those tasks completed or one errored
if x.exception() is not None or y.exception() is not None:
await self._do_close()
else:
await asyncio.sleep(<<some amount of time between pings>>) then this task needs to be started/stopped with the client |
@ledhed2222 Thanks for the insight! Would you feel comfortable implementing this? |
Based off my research what @ledhed2222 mentioned is the correct and most widely accepted solution. Right now my workaround is to add a wrapper to the iterator which takes a timeout. Then I reconnect the websocket if we hit that timeout.
which would be used like so:
It would be nice to have this functionality within the client as well. resource: https://medium.com/@dmitry8912/implementing-timeouts-in-pythons-asynchronous-generators-f7cbaa6dc1e9 |
nah @justinr1234 - even though i wrote this i'm working on other stuff now. plus i want to pass the baton on this code to someone else. what i'd recommend is two different features:
I also drafted this PR that I hope will better explain how to use the current implementation. I'm hoping it will stop people from asking about hooks :) #545 |
Description
It seems like the xrpl.py async client doesn't handle wifi disconnections:
This is the logic it uses to see if a connection is open. Please correct me if im wrong: At first glance it looks correct since it checks self._websocket.open but since we're waiting for data from our peer, the TCP network can't tell the difference between a healthy and a broken connection when the peer isn't sending us any data. So this field never updates and the websocket doesn't close - and in turn I can't attempt to reconnect.
Oddly enough even after reconnecting the wifi the websockets don't reconnect (They only reconnect if I disconnect and reconnect the wifi quickly ~2s).
Reproduction
You can just paste the following code in a python file and run it (you need the imports). After youre seeing logs disconnect the wifi and wait about a minute, then reconnect.
If you don't wait around a minute it'll reconnect on its own, but if you wait for longer it doesnt handle reconnection.
The text was updated successfully, but these errors were encountered: