Teekeks / pyTwitchAPI

A Python 3.7 compatible implementation of the Twitch API, EventSub, PubSub and Chat
https://pytwitchapi.dev
MIT License
254 stars 38 forks source link

PubSub raises PubSubListenTimeoutException every time it tries to reconnect #222

Closed epelaez1 closed 1 year ago

epelaez1 commented 1 year ago

Hi!

Maybe it is too much to say every time. I have several logs of failed attempts to reconnect, but the program doesn't show logs of successful attempts. After digging a bit into the code, I noticed this:

When the program tries to reconnect, it closes the connection to the socket.

https://github.com/Teekeks/pyTwitchAPI/blob/0c2d5c1b520d25a52c308dcd4265880b57876f47/twitchAPI/pubsub.py#L174-L178

It then reconnects and expects to receive a nonce. But the task that handles the received messages does not work anymore because the connection was closed:

https://github.com/Teekeks/pyTwitchAPI/blob/0c2d5c1b520d25a52c308dcd4265880b57876f47/twitchAPI/pubsub.py#L296-L299

I think it works fine at startup because it runs the self.__connect method before the self.__task_receive method.

https://github.com/Teekeks/pyTwitchAPI/blob/0c2d5c1b520d25a52c308dcd4265880b57876f47/twitchAPI/pubsub.py#L241-L250

Please check if this makes sense. Maybe it was a problem with my connection and theres is something im not seeing.

Thanks for this library btw. It's helping a lot!