question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RealtimeDatabase randomly closes connection - Connection interrupted for: connection_idle

See original GitHub issue

Step 2: Describe your environment

  • Android Studio version: 4.1.1
  • Firebase Component: Database
  • Component version: 19.6.0

Step 3: Describe the problem

App randomly loses connection with Realtime Database before trying to get some data from it. When the issue occurs, restarting the app solves the problem but it is annoying for the users. Reproduced on Samsung S10+ (Android 10) and Nexus 5X (Android 8.1). The strange thing is when get() call fails and the app tries to write something into the Realtime Databases, right away, the set call works.

Steps to reproduce:

It happens randomly, like 3 out of 10 app starts or GET calls. Log:

2021-01-30 16:12:12.210 9157-9599/rs.fourexample.oab D/PersistentConnection: pc_0 - Connection interrupted for: connection_idle
2021-01-30 16:12:12.221 9157-9599/rs.fourexample.oab D/Connection: conn_0 - closing realtime connection
2021-01-30 16:12:12.221 9157-9599/rs.fourexample.oab D/WebSocket: ws_0 - websocket is being closed
2021-01-30 16:12:12.224 9157-9599/rs.fourexample.oab D/PersistentConnection: pc_0 - Got on disconnect due to OTHER
2021-01-30 16:12:12.372 9157-9599/rs.fourexample.oab D/WebSocket: ws_0 - closed
2021-01-30 16:13:07.094 9157-9166/rs.fourexample.oab I/zygote64: Debugger is no longer active
2021-01-30 16:13:08.682 9157-9599/rs.fourexample.oab D/Persistence: Starting transaction.
2021-01-30 16:13:08.687 9157-9599/rs.fourexample.oab D/Persistence: Saved new tracked query in 3ms
2021-01-30 16:13:08.705 9157-9599/rs.fourexample.oab D/Persistence: Transaction completed. Elapsed: 22ms
2021-01-30 16:13:11.708 9157-9599/rs.fourexample.oab D/PersistentConnection: pc_0 - get 1 timed out waiting for connection
2021-01-30 16:13:11.713 9157-9157/rs.fourexample.oab I/RepoOperation: get for query /bloodRequests/rs falling back to cache after error: Client is offline
2021-01-30 16:13:11.715 9157-9157/rs.fourexample.oab D/Persistence: Starting transaction.
2021-01-30 16:13:11.718 9157-9157/rs.fourexample.oab D/Persistence: Saved new tracked query in 2ms
2021-01-30 16:13:11.726 9157-9157/rs.fourexample.oab D/Persistence: Transaction completed. Elapsed: 9ms
2021-01-30 16:13:11.741 9157-9157/rs.fourexample.oab E/BloodRequestService: java.lang.Exception: Client is offline
        at com.google.firebase.database.connection.PersistentConnectionImpl$2.run(PersistentConnectionImpl.java:432)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:457)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
        at java.lang.Thread.run(Thread.java:764)

Relevant Code:

Some of the Queries this occurs

// BloodRequestService.kt
val dataSnapshot = firebaseRoutes.getBloodRequestsReference(countryCode)
                .orderByChild("isActive").equalTo(true)
                .limitToFirst(20)
                .get()
                .await()

// UserService.kt
val dataSnapshot = firebaseRoutes.getUsersReference()
                .orderByKey()
                .equalTo(userId)
                .limitToFirst(1)
                .get()
                .await()

Dependencies

    // firebase
    implementation platform('com.google.firebase:firebase-bom:26.4.0')
    implementation 'com.google.firebase:firebase-analytics-ktx'
    implementation 'com.google.firebase:firebase-auth-ktx'
    implementation 'com.google.firebase:firebase-messaging-ktx'
    implementation 'com.google.firebase:firebase-database-ktx'
    implementation 'com.firebaseui:firebase-ui-auth:6.2.0'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.1.1'

    // google stuff
    implementation 'com.google.android.gms:play-services-auth:19.0.0'

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
schmidt-sebastiancommented, Feb 5, 2021

I am pretty sure I have a fix for this: https://github.com/firebase/firebase-android-sdk/pull/2414

1reaction
dimiitpkcommented, Jan 31, 2021

@UkiUros pozdrav za balkan 😃

This is the way I am using it. I am just using it for Single Item value, no lists. If u try with lists, give me feedback, buy I think its going with “.children” on snapshot…

override suspend fun getVenueFromBooking(venueId: String) =
        database
            .child(VENUES_COLLECTION)
            .child(venueId)
            .awaitQueryValue<VenueRemote>()
            .let {
                venueMapper.mapFromEntity(it)
            }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Android Realtime database throws error: client is offline but it's ...
This would randomly close connection with Realtime Database. I came up with a workaround using extensions until they solve it on their end....
Read more >
Troubleshoot common connection issues to Azure SQL ...
These connection problems can be caused by reconfiguration, firewall settings, a connection timeout, incorrect login information, or failure to ...
Read more >
Database Host Server Connections Drop after a Period ... - IBM
NET data provider, and data transfer. The cause of the problem is an idle timer in the network. This timer is typically a...
Read more >
Firewall dropping connection every ~50 days - Cisco Community
Our Oracle database server is behind the Cisco ASA firewall and after every 50 days, it randomly drops/closes few connections from its side,...
Read more >
A reason for unexplained connection timeouts on Kubernetes ...
SNAT is performed by default on outgoing connections with… ... rules out some random network failures and speaks more for a network device ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found