step-up-labs / firebase-database-dotnet

C# library for Firebase Realtime Database.
MIT License
672 stars 168 forks source link

Realtime streaming silently stops after 1 hour #257

Open ghost opened 3 years ago

ghost commented 3 years ago

I am using SignInWithCustomTokenAsync() and everything works fine except for fact that after around one hour it just stops receiving all subscribed events. I believe that can be related to a token being expired but it is supposed to still get subscribed events because token itself may be expired but the session should not have according to google documentation

The time, in seconds since the UNIX epoch, at which the token expires. It can be a maximum of 3600 seconds later than the iat. Note: this only controls the time when the custom token itself expires. But once you sign a user in using signInWithCustomToken(), they will remain signed in into the device until their session is invalidated or the user signs out.

And for other SDKs, like iOS and Android, the same way, Realtime Database automatically handles the extension of a current session, and I was expecting, and trying to get similar flow. I tried to refresh the token every time its expired but that is similar to new sign in, loads up all the subscribed events and there are hundreds or thousands of duplicates every hour (for example chatting) and the gap between expiration and the refresh is missed completely until it is fetched after refresh and filtered out. Unless I spam it every second near to expiration. If Im using the library wrong way, pls let me know. Or should I just keep using it and ignore duplicates by filtering them out. I worry about huge possible load in memory every 60 minutes. I just want subscribed events keep coming until I dispose the subscription.

Debugging / testing this is even more uncomfortable that I have to wait 1 hour.. every time. So any help would be greatly appreciated..

ghost commented 3 years ago

@bezysoftware pls one minute of your attention, if possible

190

cleytoncoro commented 3 years ago

Exactly 1 hour?

In my case, when internet goes offline for some seconds, the extension starts to use high cpu and stops to detect realtime db downstream. my workaround was to dispose firebase subscription and restart it again.

bezysoftware commented 3 years ago

I'm afraid I don't have a good solution. The library uses REST unlike the other official sdks which use their own protocol. Extending an auth token after the original one expired will cause all data to be re-fetched, as you observed, there is unfortunately no way to specify "last seen item" to skip the previous ones. There is an offline DB support within the library, but it's (by design, since it's fairly unstable and has some drawbacks) undocumented.

If I remember correctly proactively refreshing the token before it expires will not help either, because the token is part of the url used when opening the stream and I don;t think there is a way to extend it.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Unterable commented 2 years ago

after an hour my stream stops listening

BenjamimRodrigo commented 2 years ago

I have the same problem. 😪

bilalsaeed commented 1 year ago

Is there any solution yet?

@BenjamimRodrigo @nonpensavo @Unterable ?

CristiT0ma commented 1 year ago

There is an exception thrown after 1 hour. It's caused by the Auth token that expires exactly in 1 hour.

The event is there in the ProcessServerData:

case FirebaseServerEventType.AuthRevoked: break;

But as you see it does not do anything, even if it's clear that the server revoked the token. It should be added and event to shut down the processing thread and to signal this back. In fact, maybe there should be a status callback as well, not just a data update. This way you can do obtain a new auth token and restart the listening. Also, the same scenario applies if you loose the connection for whatever reason (like loss of internet connection).

abdoutech93 commented 2 months ago

I have exactly the same behavior, after 1 hour the stream doesn't receive any new updates. Any solution ?