Firebase RealTime Database Socket connection error

I am using fireabse real time database for my application. At times it it unable to form socket connection. But requests made to API hosted on firebase cloud-fucntion works properly.
I have used following dependencies :-

    implementation 'com.google.firebase:firebase-core:16.0.4'
    implementation 'com.google.firebase:firebase-database:16.0.3'
    implementation 'com.google.firebase:firebase-storage:16.0.3'
    implementation 'com.google.firebase:firebase-auth:16.0.4'

When I turned on the debug level it gives following :-

2018-11-11 14:13:17.932 14446-14513/com.example.com D/ConnectionRetryHelper: Scheduling retry in 933ms
2018-11-11 14:13:18.867 14446-14513/com.example.com D/PersistentConnection: pc_0 - Trying to fetch auth token
2018-11-11 14:13:18.873 14446-14513/com.example.com D/PersistentConnection: pc_0 - Successfully fetched token, opening connection
2018-11-11 14:13:18.878 14446-14513/com.example.com D/Connection: conn_1 - Opening a connection
2018-11-11 14:13:48.881 14446-14513/com.example.com D/WebSocket: ws_1 - timed out on connect
2018-11-11 14:13:48.882 14446-14513/com.example.com D/WebSocket: ws_1 - closed
2018-11-11 14:13:48.882 14446-14513/com.example.com D/WebSocket: ws_1 - closing itself
2018-11-11 14:13:48.882 14446-14513/com.example.com D/Connection: conn_1 - Realtime connection failed
2018-11-11 14:13:48.882 14446-14513/com.example.com D/Connection: conn_1 - closing realtime connection

This keeps happening on certain device like Mi5 note pro, lenov

1 possible answer(s) on “Firebase RealTime Database Socket connection error

  1. Getting the same error on Firebase Realtime database 16.1.0, it doesn’t work on mobile network, but works perfectly fine on WiFi networks, also is much likely to happen on a device running Android 9.

    Logs:

    2019-03-18 16:21:12.138 D/WebSocket: ws_1 – timed out on connect
    2019-03-18 16:21:12.139 D/WebSocket: ws_1 – closed
    2019-03-18 16:21:12.139 D/WebSocket: ws_1 – closing itself
    2019-03-18 16:21:12.139 D/Connection: conn_1 – Realtime connection failed
    2019-03-18 16:21:12.139 D/Connection: conn_1 – closing realtime connection
    2019-03-18 16:21:12.139 D/PersistentConnection: pc_0 – Got on disconnect due to OTHER
    2019-03-18 16:21:12.139 D/PersistentConnection: pc_0 – Scheduling connection attempt
    2019-03-18 16:21:12.140 D/ConnectionRetryHelper: Scheduling retry in 539ms
    2019-03-18 16:21:12.682 D/PersistentConnection: pc_0 – Trying to fetch auth token
    2019-03-18 16:21:12.689 D/PersistentConnection: pc_0 – Successfully fetched token, opening connection
    2019-03-18 16:21:12.692 D/Connection: conn_2 – Opening a connection
    2019-03-18 16:21:42.697 D/WebSocket: ws_2 – timed out on connect
    2019-03-18 16:21:42.699 D/WebSocket: ws_2 – closed
    2019-03-18 16:21:42.699 D/WebSocket: ws_2 – closing itself
    2019-03-18 16:21:42.699 D/Connection: conn_2 – Realtime connection failed
    2019-03-18 16:21:42.699 D/Connection: conn_2 – closing realtime connection
    2019-03-18 16:21:42.700 D/PersistentConnection: pc_0 – Got on disconnect due to OTHER
    2019-03-18 16:21:42.700 D/PersistentConnection: pc_0 – Scheduling connection attempt
    2019-03-18 16:21:42.702 D/ConnectionRetryHelper: Scheduling retry in 580ms
    2019-03-18 16:21:43.284 D/PersistentConnection: pc_0 – Trying to fetch auth token
    2019-03-18 16:21:43.287 D/PersistentConnection: pc_0 – Successfully fetched token, opening connection

    The same snippet of message occurs in a loop.