Wednesday, 26 September 2018

Firebase Listener Not Working On Android Device (Sometimes)

My firebase listeners work perfectly on iOS (device and simulator) and the Android simulator.

When connected to a real android device, listeners sometimes do not fire.

How can I go about debugging this?

When firebase listeners aren't working, the firebase auth() function is however working. So, I can authenticate a user, but I cannot retrieve data with a .on listener.

For example,

firebase.auth().signInAndRetrieveDataWithEmailAndPassword(email, pass)
.then(() => {
    console.log('this prints every time');
})
.catch(function (error) {
    console.log(error);
});

firebase.auth().onAuthStateChanged((user) => {
    if (user) {
        firebase.database().ref().on('value', (snapshot) => {
            console.log('This never prints')
        });
    }
}

The .on listener doesn't fire, but the authentication works.

This only happens sometimes and usually waiting several hours and trying again makes it go away. Then it'll come back again.

EDIT: After a little over an hour of waiting with the app open, the firebase listeners actually worked. But, it took more than an hour. Still have no idea why...

EDIT: Found these logs inside logcat in Android Studio. This same set of messages are repeated over and over again.

EDIT: When connecting to the internet using a mobile hotspot, the issue does NOT occur...

09-23 22:25:47.920 21028-21146/com.starco.starmsg D/PersistentConnection: pc_0 - Trying to fetch auth token
09-23 22:25:47.923 21028-21146/com.starco.starmsg D/PersistentConnection: pc_0 - Successfully fetched token, opening connection
09-23 22:25:47.924 21028-21146/com.starco.starmsg D/Connection: conn_5 - Opening a connection
09-23 22:25:49.163 21028-21372/com.starco.starmsg V/FA: Inactivity, disconnecting from the service
09-23 22:26:17.925 21028-21146/com.starco.starmsg D/WebSocket: ws_5 - timed out on connect
    ws_5 - closed
    ws_5 - closing itself
09-23 22:26:17.925 21028-21146/com.starco.starmsg D/Connection: conn_5 - Realtime connection failed
    conn_5 - closing realtime connection
09-23 22:26:17.925 21028-21146/com.starco.starmsg D/PersistentConnection: pc_0 - Got on disconnect due to OTHER
09-23 22:26:17.926 21028-21146/com.starco.starmsg D/PersistentConnection: pc_0 - Scheduling connection attempt
09-23 22:26:17.926 21028-21146/com.starco.starmsg D/ConnectionRetryHelper: Scheduling retry in 2547ms
09-23 22:26:18.991 21028-21146/com.starco.starmsg D/WebSocket: ws_5 - WebSocket error.
    bfz: error while creating secure socket to wss://star-msg.firebaseio.com/.ws?ns=star-msg&v=5
        at bfw.d(:com.google.android.gms.dynamite_dynamitemodulesc@13280045@13.2.80 (040304-211705629):86)
        at bfx.run(:com.google.android.gms.dynamite_dynamitemodulesc@13280045@13.2.80 (040304-211705629):3)
        at java.lang.Thread.run(Thread.java:761)
     Caused by: java.net.ConnectException: Connection timed out
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:334)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:196)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:356)
        at java.net.Socket.connect(Socket.java:586)
        at com.android.org.conscrypt.OpenSSLSocketImpl.connect(OpenSSLSocketImpl.java:265)
        at com.android.org.conscrypt.OpenSSLSocketImpl.connect(OpenSSLSocketImpl.java:252)
        at java.net.Socket.<init>(Socket.java:427)
        at java.net.Socket.<init>(Socket.java:210)
        at javax.net.ssl.SSLSocket.<init>(SSLSocket.java:906)
        at com.android.org.conscrypt.OpenSSLSocketImpl.<init>(OpenSSLSocketImpl.java:192)
        at com.android.org.conscrypt.OpenSSLSocketFactoryImpl.createSocket(OpenSSLSocketFactoryImpl.java:68)
        at bfw.d(:com.google.android.gms.dynamite_dynamitemodulesc@13280045@13.2.80 (040304-211705629):70)
        at bfx.run(:com.google.android.gms.dynamite_dynamitemodulesc@13280045@13.2.80 (040304-211705629):3) 
        at java.lang.Thread.run(Thread.java:761) 



from Firebase Listener Not Working On Android Device (Sometimes)

No comments:

Post a Comment