[Unity] What is the intended behaviour when I am trying to push data after the internet connection is lost?

269 views
Skip to first unread message

Johan Gustafsson

unread,
Dec 19, 2016, 11:02:39 AM12/19/16
to Firebase Google Group
Hello people,

I using the new Unity SDK in my project and I found something interesting while killing my internet to debug the app.

When I auth a user with a Facebook credential I also get a reference to the Firebase database using "highscoreRef = FirebaseDatabase.DefaultInstance.GetReference("highscores");".
I do this so I only need to fetch it once and I have noticed that it will speed up subsequent calls to the same reference.

After a game round has been completed I push the score to the highscore database using:

        string highscoreEntryKey = highscoreRef.Push().Key;

        highscoreRef.Child(highscoreEntryKey).SetRawJsonValueAsync(sb.ToString()).ContinueWith(
            (task) => {
                if (task.IsCanceled || task.IsFaulted) {
                    callback(false);
                }
                else {
                    callback(true);
                }
            }
        );

However, I found that if I cut the internet connection between getting the first database ref and pushing to the database, the "highscoreRef.Child(highscoreEntryKey).SetRawJsonValueAsync(sb.ToString())" will not work properly.
First of all it's ContinueWith thread will never fire and secondly it seems that it fails completely silent so I have no way of detecting if the operation was successful or not.

Is this the expected behaviour and if so how can I make sure that it will fail before calling it so I know how to script the game's behaviour correctly.


Best regards Johan

Kato Richardson

unread,
Dec 19, 2016, 1:47:46 PM12/19/16
to Firebase Google Group
Hi Johan,

Does `ContinueWith` trigger after the network connection is reestablished? Obviously, it wouldn't be able to trigger a callback saying that the async write event completed until there is internet connectivity, so that would be my expectation here.

☼, Kato

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/231c837d-6e42-4939-939c-57c4ff6c1712%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

Johan Gustafsson

unread,
Dec 19, 2016, 4:44:14 PM12/19/16
to Firebase Google Group
In addition to what I said above. Let's say I manage to detect that there is no internet connection and informs the user that this is the case. If the user then reconnects and I try to call highscoreRef.Child(highscoreEntryKey).SetRawJsonValueAsync(sb.ToString()).ContinueWith now with a good internet connection the same thing still happens. It just fails silently and I get no callback at all. How am I supposed to "restart" the firebase session appropriately so that I can continue using it?
I tried using the static FirebaseDatabase methods GoOnline() but to no avail.

Johan Gustafsson

unread,
Dec 20, 2016, 11:17:25 AM12/20/16
to Firebase Google Group
Hello Kato,

No it does not. Even if I re-establish a working internet connection the ContinueWith will never run so I will never get any callback. As I said in my other response, even if I call the SetRawJsonValueAsync after re-establishing a connection it will never fire ContinueWith. So basically the database connection kinda breaks down. I'm not sure what the best way would be to restart it. Maybe I'm missing something.

Best regards Johan



Den måndag 19 december 2016 kl. 19:47:46 UTC+1 skrev Kato Richardson:
Hi Johan,

Does `ContinueWith` trigger after the network connection is reestablished? Obviously, it wouldn't be able to trigger a callback saying that the async write event completed until there is internet connectivity, so that would be my expectation here.

☼, Kato
On Mon, Dec 19, 2016 at 7:14 AM, Johan Gustafsson <johan....@gmail.com> wrote:
Hello people,

I using the new Unity SDK in my project and I found something interesting while killing my internet to debug the app.

When I auth a user with a Facebook credential I also get a reference to the Firebase database using "highscoreRef = FirebaseDatabase.DefaultInstance.GetReference("highscores");".
I do this so I only need to fetch it once and I have noticed that it will speed up subsequent calls to the same reference.

After a game round has been completed I push the score to the highscore database using:

        string highscoreEntryKey = highscoreRef.Push().Key;

        highscoreRef.Child(highscoreEntryKey).SetRawJsonValueAsync(sb.ToString()).ContinueWith(
            (task) => {
                if (task.IsCanceled || task.IsFaulted) {
                    callback(false);
                }
                else {
                    callback(true);
                }
            }
        );

However, I found that if I cut the internet connection between getting the first database ref and pushing to the database, the "highscoreRef.Child(highscoreEntryKey).SetRawJsonValueAsync(sb.ToString())" will not work properly.
First of all it's ContinueWith thread will never fire and secondly it seems that it fails completely silent so I have no way of detecting if the operation was successful or not.

Is this the expected behaviour and if so how can I make sure that it will fail before calling it so I know how to script the game's behaviour correctly.


Best regards Johan

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/231c837d-6e42-4939-939c-57c4ff6c1712%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kato Richardson

unread,
Dec 20, 2016, 11:26:29 AM12/20/16
to Firebase Google Group

Well, the options here are 1) A Firebase bug is preventing reconnect, 2) Authentication creds are expiring while offline and not being re-established before the write event takes place or 3) something in security rules is causing the write to be rejected (I supposed we’d still expect the callback to trigger in #3).

It’ll help to include all the relevant code, sample data, debug logging, and version info so we can fully understand the problem. See how to ask and creating an mcve.

☼, Kato


To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Johan Gustafsson

unread,
Dec 21, 2016, 10:27:35 AM12/21/16
to Firebase Google Group
Hello Kato,

Thanks for taking your time helping me out.
Seeing as this does not seem to be the intended behaviour I've instead created a support ticket through the main support channel (https://firebase.google.com/support/).


Best regards,
Johan.
Reply all
Reply to author
Forward
0 new messages