RealtimeDatabase randomly closes connection – Connection interrupted for: connection_idle

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.

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 java.util.concurrent.Executors$
        at java.util.concurrent.ScheduledThreadPoolExecutor$
        at java.util.concurrent.ThreadPoolExecutor.runWorker(
        at java.util.concurrent.ThreadPoolExecutor$

Relevant Code:

Some of the Queries this occurs

// BloodRequestService.kt
val dataSnapshot = firebaseRoutes.getBloodRequestsReference(countryCode)

// UserService.kt
val dataSnapshot = firebaseRoutes.getUsersReference()


    // firebase
    implementation platform('')
    implementation ''
    implementation ''
    implementation ''
    implementation ''
    implementation 'com.firebaseui:firebase-ui-auth:6.2.0'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-play-services:1.1.1'

    // google stuff
    implementation ''

1 possible answer(s) on “RealtimeDatabase randomly closes connection – Connection interrupted for: connection_idle