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

"Lost connection to server" on every little connection error/timeout #738

Open
matkuki opened this issue Mar 20, 2023 · 6 comments
Open

Comments

@matkuki
Copy link
Contributor

matkuki commented Mar 20, 2023

Hi @almarklein

I have an application that is running on a server that is accessed through a VPN, which works great.
But every little hiccup for even a split second in the connection gives the "Lost connection to server" error.

Is there a way to mitigate this, maybe with inserting a retry somewhere?

Thanks

@almarklein
Copy link
Member

Websockets are indeed more susceptible to connection problems. Technically it should be possible to restore the connection, but I fear that would involve substantial changes to the Flexx internals, because the session is very much tied to the websocket connection right now ...

@matkuki
Copy link
Contributor Author

matkuki commented Mar 21, 2023

No problem, was just wondering if there was a simple workaround.
Thanks for the information.

@matkuki matkuki closed this as completed Mar 21, 2023
@matkuki
Copy link
Contributor Author

matkuki commented Mar 31, 2023

Hey @almarklein ,
I looked at some of the source and there are quite a few self.ws or self._ws references.
If I would update all of those references with a new WebSocket when on_ws_close (flexx/app/_clientcore.py line 347) is called, would that work?

@matkuki matkuki reopened this Mar 31, 2023
@almarklein
Copy link
Member

I'm not sure, but it could be worth a try ...

@matkuki
Copy link
Contributor Author

matkuki commented Apr 5, 2023

Hey @almarklein

I tried a bit of fiddling around, but now I'm getting the error Asked for session id X, but could not find it when trying to reconnect the socket.
My main problem is that I do not have an idea of how the websocket initialization chain is processed. Could you give me a point-by-point description of the websocket initialization order of the methods needed to initialize and then communicate with the JS side?

Thanks

@almarklein
Copy link
Member

That error originates here:

flexx/flexx/app/_app.py

Lines 601 to 612 in 7461524

def connect_client(self, ws, name, session_id, cookies=None):
""" Connect a client to a session that was previously created.
"""
_, pending, connected = self._appinfo[name]
# Search for the session with the specific id
for session in pending:
if session.id == session_id:
pending.remove(session)
break
else:
raise RuntimeError('Asked for session id %r, but could not find it' %
session_id)

An incoming connection asks the manager to find the corresponding session. In this case it fails, because it looks in the pending sessions, and it's not there.

The session lifetime has a few stages:

STATUS = new_type('Enum', (), {'PENDING': 1, 'CONNECTED': 2, 'CLOSED': 0})

I think we'd need to add another stage, maybe LOST, from which we can reconnect. The manager will also have to keep track of lost sessions in its _appinfo data structure. Though we'd also need a mechanism to purge LOST sessions once they're lost for too long.

I hope this helps ...

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