firebase-database-dotnet icon indicating copy to clipboard operation
firebase-database-dotnet copied to clipboard

Realtime streaming silently stops after 1 hour

Open ghost opened this issue 4 years ago • 9 comments

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 avatar Dec 23 '20 04:12 ghost

@bezysoftware pls one minute of your attention, if possible #190

ghost avatar Dec 23 '20 04:12 ghost

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.

cleytoncoro avatar Jan 22 '21 16:01 cleytoncoro

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.

bezysoftware avatar Jun 21 '21 18:06 bezysoftware

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.

stale[bot] avatar Jan 09 '22 01:01 stale[bot]

after an hour my stream stops listening

Unterable avatar Mar 25 '22 19:03 Unterable

I have the same problem. 😪

BenjamimRodrigo avatar Aug 27 '22 11:08 BenjamimRodrigo

Is there any solution yet?

@BenjamimRodrigo @nonpensavo @Unterable ?

bilalsaeed avatar Mar 16 '23 20:03 bilalsaeed

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).

CristiT0ma avatar Apr 18 '23 15:04 CristiT0ma