cheshire-cat-ai/core

Close ws connections inactive for more than x seconds

Opened this issue · 9 comments

At the moment all ws connections remain open forever XD
We can check the old ones and close them, maybe using the WhiteRabbit by @jacopopalumbo01 or (tmp) just running a loop on active connections when a new user tries to connect, and close the old inactive ones

Can be done with the WhiteRabbit

I'm here

I don't think the WhiteRabbit is needed. Check this out: https://stackoverflow.com/questions/63847205/fastapi-websocket-ping-pong-timeout and https://websockets.readthedocs.io/en/stable/topics/timeouts.html#keepalive-in-websockets (the library used under the hood)

Awesome!
So I guess we just need to delete the stray once ws disconnects

# del strays[user_id]

Or there was a reason for not deleting it?
Can you remember @Pingdred ?

Or there was a reason for not deleting it?
Can you remember @Pingdred ?

We chose not to delete it just to preserve Working Memory in case of disconnection

And deleting the stray instance may arise problems when an action using the stray is scheduled in the WhiteRabbit.

Proposal:
As soon as the stray is created, white rabbit will check every x minutes if it is active or not
If not, it gets deleted

Unless as @jacopopalumbo01 said there is a breaking dependency between the objects

After 23/09/2024 dev meeting:

Have a new SessionManager that is used here to store, get, create and delete expired StrayCat objects