TwitchLib / TwitchLib.PubSub

PubSub component of TwitchLib.
38 stars 52 forks source link

PubSub Connection Error #111

Closed A5ho9999 closed 1 year ago

A5ho9999 commented 1 year ago

This issue ( #96 ) has started to appear a lot again, it was fine a couple months then it started to spam the error every month or so, now it's happening every couple days. It's starting to get rather annoying as no matter would I do it loops the connection over and over with no way of disconnecting even if the disconnect is called. Only way to stop is to complete restart the application.

The error information given has changed slightly though but other than I don't have any other information on it. Even though it doesn't state in anyway that it's a PubSub error it's only being triggered the in the PubSub Error event

The operation was canceled.
System.Private.CoreLib
System.Collections.ListDictionaryInternal
   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at System.Collections.Concurrent.BlockingCollection`1.TryTakeWithNoTimeValidation(T& item, Int32 millisecondsTimeout, CancellationToken cancellationToken, CancellationTokenSource combinedTokenSource)
   at TwitchLib.Communication.Services.Throttlers.<StartWhisperSenderTask>b__29_0()
The operation was canceled.
System.Private.CoreLib
System.Collections.ListDictionaryInternal
   at System.Threading.CancellationToken.ThrowOperationCanceledException()
   at System.Collections.Concurrent.BlockingCollection`1.TryTakeWithNoTimeValidation(T& item, Int32 millisecondsTimeout, CancellationToken cancellationToken, CancellationTokenSource combinedTokenSource)
   at TwitchLib.Communication.Services.Throttlers.<StartSenderTask>b__28_0()
Syzuna commented 1 year ago

I am a bit swamped atm but I will try to look into it this weekend or start of next week

A5ho9999 commented 1 year ago

No worries, I've had to just disable it for the moment as it started to happen every couple of hours after restarting the program. Really wish there was more information that I could provide but there is none.

Inzaniity commented 1 year ago

Yeah I see that behavior too, and can confirm that only a full restart of the application is the solution.

A5ho9999 commented 1 year ago

Yeah doesn't seem to be getting any better lately, longest it's remained connected in the past month is about 32 hours. I've even tried adjusting the ThrottlingPeriod within the Twitch Client to see if that helped in anyway and it did not.

CrunchEnergy commented 1 year ago

I'm having the same various connection/reconnection, and unable to disconnect problems, and have just seen TwitchLib.Communication which PubSub uses for it's websocket had a 1.0.6 release a few days ago, which fixed a reconnect loop on disconnect bug. Might be worth upgrading and seeing if it helps at all.

Inzaniity commented 1 year ago

I'm having the same various connection/reconnection, and unable to disconnect problems, and have just seen TwitchLib.Communication which PubSub uses for it's websocket had a 1.0.6 release a few days ago, which fixed a reconnect loop on disconnect bug. Might be worth upgrading and seeing if it helps at all.

Have you encountered the disconnect and were able to successfully reconnect again? If so, then its a good starting point. As of yet I disabled pubsub in my application and listen for the rewards in tmi since I always have an input in my case. Still pubsub is the better solution.

A5ho9999 commented 1 year ago

I'm having the same various connection/reconnection, and unable to disconnect problems, and have just seen TwitchLib.Communication which PubSub uses for it's websocket had a 1.0.6 release a few days ago, which fixed a reconnect loop on disconnect bug. Might be worth upgrading and seeing if it helps at all.

I have updated yes, it remained connected for around 3 days and then disconnected this morning however didn't automatically try to reconnect so it appears it no longer loops. However I am going to give it another week or so to confirm if the looping is fixed.

Inzaniity commented 1 year ago

I'm having the same various connection/reconnection, and unable to disconnect problems, and have just seen TwitchLib.Communication which PubSub uses for it's websocket had a 1.0.6 release a few days ago, which fixed a reconnect loop on disconnect bug. Might be worth upgrading and seeing if it helps at all.

I have updated yes, it remained connected for around 3 days and then disconnected this morning however didn't automatically try to reconnect so it appears it no longer loops. However I am going to give it another week or so to confirm if the looping is fixed.

Tried it myself, got an error, and tried to call Disconnect() and Connect() after, but this didn't work and led to loops again, throwing more and more errors until I eventually had to restart the application. I think I will just go by my previous solution to just disable PubSubs altogether until it's fixed.

CrunchEnergy commented 1 year ago

Tried it myself, got an error, and tried to call Disconnect() and Connect() after, but this didn't work and led to loops again, throwing more and more errors until I eventually had to restart the application. I think I will just go by my previous solution to just disable PubSubs altogether until it's fixed.

My reconnection handling does seem to work OK now. I think it has auto reconnect, but when I get a disconnect/error I start a small timer (To dedupe the multiple error/disconnect events) to: revalidate oauth tokens, re-call the ListenToXXX() functions, and then call Connect(). I also don't bother calling .Disconnect() on error because its slow.

Before you reconnect, are you re-calling the various ListenToXXX() functions? It doesn't seem to internally remember the topics you subscribed to between connections. Could it be PubSub disconnecting you after X seconds of no topic subscriptions? Are you checking the oauth token is still valid too?

A5ho9999 commented 1 year ago

Well the main issue of looping seems to be fixed, and so far as reconnected and stay connected without issue. Though still unsure why it would be giving the error in the first place.