Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Aborting transactions for path" when saving object to Firebase on Android

I'm having issues with some code which was working fine until today. Basically, i'm doing the standard create user object after auth for extra data.

But, when i was just testing the code below it no longer enters the onComplete method. Instead, i get the error in the log below about the transaction being aborted.

A Google brings up nothing, what could it be?

Code:

final Firebase userLocation = new Firebase(Constants.USERS_URL).child(uid);

    User newUser = new User(name, email);

    userLocation.setValue(newUser, new Firebase.CompletionListener() {
        @Override
        public void onComplete(FirebaseError firebaseError, Firebase firebase) {
            if(firebaseError == null) {
                ...
            }
            else {
                ...
            }
        }
    });

Logs:

04-05 16:13:04.274 4855-4912/com.nicedistractions.bestbefore D/AuthenticationManager: Sending request to https://auth.firebase.com/v2/best-before/users with 2 query params
04-05 16:13:05.437 4855-4855/com.nicedistractions.bestbefore I/RegisterPresenter: Successfully created user account with uid: 4a97cb4b-4034-4f46-98c3-4104d1d649b7
04-05 16:13:05.437 4855-4855/com.nicedistractions.bestbefore D/RegisterPresenter: Creating user object
04-05 16:13:05.484 4855-4912/com.nicedistractions.bestbefore D/WebSocket: ws_1 - Reset keepAlive. Remaining: 0
04-05 16:13:05.502 4855-4912/com.nicedistractions.bestbefore D/RepoOperation: set: /users/4a97cb4b-4034-4f46-98c3-4104d1d649b7
04-05 16:13:05.503 4855-4912/com.nicedistractions.bestbefore D/DataOperation: set: /users/4a97cb4b-4034-4f46-98c3-4104d1d649b7 {
                                                                                [email protected]
                                                                                name=xxxxx xxxxxxxx
                                                                                timestampJoined={
                                                                                  timestamp={.sv=timestamp}
                                                                                }
                                                                              }
04-05 16:13:05.503 4855-4912/com.nicedistractions.bestbefore D/Persistence: Starting transaction.
04-05 16:13:05.524 4855-4912/com.nicedistractions.bestbefore D/Persistence: Persisted user overwrite in 20ms
04-05 16:13:05.536 4855-4912/com.nicedistractions.bestbefore D/Persistence: Transaction completed. Elapsed: 33ms
04-05 16:13:05.538 4855-4912/com.nicedistractions.bestbefore D/RepoOperation: Aborting transactions for path: /users/4a97cb4b-4034-4f46-98c3-4104d1d649b7. Affected: /users/4a97cb4b-4034-4f46-98c3-4104d1d649b7

Thanks for your help!

like image 743
Luke Avatar asked Apr 05 '16 22:04

Luke


1 Answers

I am able to reproduce this on Lollipop when I am connected to wifi, disable the actual internet connectivity, and then re-enable internet connection (all with the device remaining connected to wifi network). After this, if I try to perform a setValue() write, about 18 minutes will pass before Firebase reconnects and the setValue() completes. I reached out to the Firebase team and was told this is expected behavior due to the Android OS basically neglecting to informing apps when the connection is restored.

The only way to resolve in my experience is either disabling and re-enabling WiFi, or restarting the app (restarting the activity won't help).

Firebase support got back to me and suggested calling goOffline() followed by goOnline() - I verified this immediately reconnects the Firebase database. What I do now is set a Handler with my own timeout for setValue(), since I can't seem to depend on DatabaseError being thrown with onComplete().

like image 170
policenauts Avatar answered Nov 03 '22 06:11

policenauts