“Aborting transactions for path” when saving object to Firebase on Android Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of “Aborting transactions for path” when saving object to Firebase on Android without wasting too much if your time.

The question is published on by Tutorial Guruji team.

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=xxxxxxxxxx@gmail.com
                                                                                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!

Answer

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

We are here to answer your question about “Aborting transactions for path” when saving object to Firebase on Android - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji