-
Notifications
You must be signed in to change notification settings - Fork 658
[BUG]: Duplicate connections when the previous connection was not closed. #724
Comments
should be fixed in #708 |
This pull request has not solved the issue. I hope you understood my explanations. |
#708 aimed at the local Channelmanager, maybe something similar is hidden in the redis manager |
Debugging this line could be helpful and when the method is being called. |
@myckhel Starting with a Redis database fixes the job? It seems like the Lock might already exist in Redis and won't pass the checks: https://github.com/simonbuehler/laravel-websockets/blob/0dc2db12c43a344249149f26815f20edf96ff421/src/ChannelManagers/RedisChannelManager.php#L378 |
You meant restarting? screen shot of my redis db with lot of unused or expired sockets really dont know much about redis programmatically but i tried to do little and discovered the callback at never gets called: https://github.com/simonbuehler/laravel-websockets/blob/0dc2db12c43a344249149f26815f20edf96ff421/src/ChannelManagers/RedisChannelManager.php#L378 here is the screenshot of the debug if the callback was ever called |
Debugging Further.from the referenced line function: https://github.com/simonbuehler/laravel-websockets/blob/0dc2db12c43a344249149f26815f20edf96ff421/src/ChannelManagers/RedisChannelManager.php#L378 i tried moving the callback from inside and above the $this->getConnectionsFromSet(0, now()->subMinutes(1)->format('U'))
->then(function ($connections) {
foreach ($connections as $socketId => $appId) {
$connection = $this->fakeConnectionForApp($appId, $socketId);
dump($socketId, $connection);
$this->unsubscribeFromAllChannels($connection);
}
}); i reduced Now i tried to reproduce the bug but this time everything worked fine as expected. Reproduction
After above reproduction steps and while refreshing the redis db to see changes within one minute. when 1 minute passed, i tried to refresh the db again to see if the (the previous connection which was not properly closed is still active in the db) but it was gone which means the function actually worked for connections that didint pong within 1 minute. so i guess there is something wrong with the redis lock. |
Manually deleting the i think some how the redis lock was not released and being persistent in the db forever. and every time websocket tries to attempt a lock then the lock is always busy because it was never released. so the maybe there should be a way to forceRelease the lock if being locked for Update: I think it should be a good idea to have then from the a similar approach will fix the issue when the redis lock was never released. |
protected function lock()
{
// set the expire time to 5 secs. // debugging purpose only
return new RedisLock($this->redis, static::$lockName, 5);
} AND public function release()
{
return (bool) true;//$this->redis->eval(LuaScripts::releaseLock(), 1, $this->name, $this->owner);
} Automatically redis will delete the so setting an expiry seconds will be better. |
Any news for this issue? I also have the exact problem |
@zek Only if you need the fix asap before being officially fixed. i suggest you install the pulled_request branch temporarily and try it out. Steps
"require": {
...
"beyondcode/laravel-websockets": "dev-redis-lock-timeout",
...
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/myckhel/laravel-websockets.git"
}
], composer update |
@myckhel I've tried it however I still have some issues. I stopped using redis database but it still persist. So I guess there're some other problems. |
did you try to delete the lock key ( after i did that i have not had any issue like that since then. |
i discovered too. redis lock timeout solved some part of the issues. i guess it does not removeObsoleteConnections for other users which their connections are Obsolete but only removes for the current user i guess. |
hey @myckhel any new findings or updates here ? |
@danyelkeddah i guess i will have to debug |
Uh oh!
There was an error while loading. Please reload this page.
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:now if i unsubscribe from
presence-user.1-online
the459436735.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 channelpresence-user.1-online
now i have duplicate subscriptions:
when i unsubscribe i will have:
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
.The text was updated successfully, but these errors were encountered: