TwitchIO icon indicating copy to clipboard operation
TwitchIO copied to clipboard

Dirty cache in websocket.py when reconnect to network

Open duffy356 opened this issue 2 years ago • 3 comments

I have encountered an issue with reconnects or changes of the network while running the bot.

When the network connection is dead for less than one minute, the cached connections from the websocket may still work, but when the network is offline for more than 5 minutes, then the websocket will reconnect, but the previous connections from the websocket._cache dictionary are outdated and dead. The Library will not connect automatically to the previously connected channels.

I could fix it for my concrete usage with an overloaded version of the following method in Client's subclass:

async def event_ready(self):
    # We are logged in and ready to chat and use commands...
    self._logger.info(f'Logged in on Twitch as | {self.nick}')
    if len(self._connection._cache) > 1:
        keys_to_delete = []
        for key in self._connection._cache.keys():
            if key != "duffy356":
                self._logger.info(f"logged in with {key} in cache")
                keys_to_delete.append(key)

        for key in keys_to_delete:
            del self._connection._cache[key]
        self._logger.info(f"removed all users from cache that were outdated!")

It would be nice to automatically reconnect to the connected channels from the websocket's cache or at least remove the entries from the cache, so that a new call of join_channels("a") will allow the library to make a new connection to channel "a".

duffy356 avatar Nov 22 '21 21:11 duffy356

I assume this has not been resolved? I do believe this is an issue I'm encountered now..

when my PC is put to sleep for more than a few minutes then when coming back online the chatbot is no longer connected.. although some parts of it do seem to still be active which is a bit odd.

gitagogaming avatar Jul 27 '22 22:07 gitagogaming

Just to verify, #364 does not resolve this, correct?

EDIT: It does not.

alkim0 avatar Apr 04 '23 08:04 alkim0

I’m having the same issue.

Nevrai avatar Jun 18 '23 06:06 Nevrai