[BUG]: Duplicate connections when the previous connection was not closed. #724
Description
I have duplicate connections and subscriptions to channels in my redis database which is causing some huge bugs.
I will first of all ask
How do we handle connections that are not active for some time?
when i make a new websocket connection i and subscribe to eg. presence-user.1-online
i think my subscription will be saved in redis db presence-user.1-online/users
with:
459436735.214668603 | {"user_id":2002,"user_info":true} |
---|
now if i unsubscribe from presence-user.1-online
the 459436735.214668603 | {"user_id":2002,"user_info":true}
will be deleted.
But bug happens if my disconnection was not handled.
e.g
if my internet goes of and i close the app then we should expect that the websocket connection was not closed when the app closed.
which means i will still have my subscription persisted in the database: 459436735.214668603 | {"user_id":2002,"user_info":true}
now i have internet and i launched the app again
i got a new websocket connection 459436736.214668604
and i tried to subscribe to the same channel presence-user.1-online
now i have duplicate subscriptions:
459436735.214668603 | {"user_id":2002,"user_info":true} |
---|---|
459436736.214668604 | {"user_id":2002,"user_info":true} |
-- | -- |
when i unsubscribe i will have:
459436735.214668603 | {"user_id":2002,"user_info":true} |
---|
i think this connection that was not closed will be there in db as long as possible causing unexpected issues.
but when i discovered this issue i was thinking this case should have been handled using something similar to the ping pong
maybe if the server pings the connection and does not respond within some amount of time then all the instances of the connection should be deleted.
i think something similar to this approach will avoid duplicate connections and cleanup unused resources in the db
.