firebase / firebase-unity-sdk

The Firebase SDK for Unity
http://firebase.google.com
Apache License 2.0
220 stars 35 forks source link

The value of Firebase.Database.ServerValue.Timestamp is different from actual value in database. #360

Closed unace closed 4 months ago

unace commented 4 years ago

Please fill in the following fields:

Unity editor version: 2019.3.0f6 Firebase Unity SDK version: 6.9.0 Firebase plugins in use (Auth, Database, etc.): Analytics, Auth, Database Additional SDKs you are using (Facebook, AdMob, etc.): Nothing. Platform you are using the Unity editor on (Mac, Windows, or Linux): Mac Platform you are targeting (iOS, Android, and/or desktop): Android Scripting Runtime (Mono, and/or IL2CPP): IL2CPP

Please describe the issue here:

The value of Firebase.Database.ServerValue.Timestamp is different from actual value in the database. I can read the actual value if I reconnect. Is there any way to get the actual value without reconnection?

var database = Firebase.Database.FirebaseDatabase.DefaultInstance;
await database.GetReference("serverTime").SetValueAsync(Firebase.Database.ServerValue.Timestamp);
var serverTimeSnapshot = await database.GetReference("serverTime").GetValueAsync();
Debug.Log(serverTimeSnapshot.ToString());

log DataSnapshot { key = serverTime, value = 1580863620000 }

actual value in database image

Please answer the following, if applicable:

Have you been able to reproduce this issue with just the Firebase Unity quickstarts (this GitHub project)? I haven't tried.

What's the issue repro rate? (eg 100%, 1/5 etc) 100%

unace commented 4 years ago

It seems that Firebase database returns local time value. After changing my machine time, the value of Firebase.Database.ServerValue.Timestamp follow the my local time. Is there any way to get the actual server value without reconnection?

paulinon commented 4 years ago

Thanks for reporting this @unace. I was also able to encounter this discrepancy on my end, even with the updated SDK. As an action, I've filed an internal bug for this issue. I can't give you any timelines for updates regarding this, so I'll leave this open.

unace commented 4 years ago

Thanks! @paulinon

argzdev commented 4 months ago

Just bumping this thread. It looks like this issue can be resolved by using our Clock skew functionality. You can add the offset needed in your local time. You may also refer to this conversation thread. And for what it's worth, I don't think there's any way for an app to get the actual server value without reconnection. I'll go ahead and close this thread.