问题
After updating my projects Firebase SDK, I noticed my app regularly lose connection with the firebase database. The time it would take to disconnect ranging from a few minutes to just over an hour. Once disconnected, the app would not reconnect until I have either logged out or cleared the apps data.
Also right before I lose connection, an entry in the log states that my auth token has expired:
PersistentConnection: pc_0 - Auth token revoked: expired_token (Auth token is expired.)
FYI, im using Twitter and Facebook for my authentication and did not experience such issues with the previous Firebase SDK.
I created a new project (with simple auth and real time database) to see if the issue persists and it does. I've attached snippets of that new project:
The build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.3"
defaultConfig {
applicationId "com.sample.gideon.test"
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.4.0'
compile 'com.android.support:support-v4:23.4.0'
compile 'com.facebook.android:facebook-android-sdk:4.12.0'
compile 'com.google.firebase:firebase-database:9.0.0'
compile 'com.google.firebase:firebase-auth:9.0.0'
compile 'com.android.support:design:23.4.0'
}
apply plugin: 'com.google.gms.google-services'
The authentication activity follows the firebase facebook login guide, which indeed successfully logs the user in and sends them to the MainActivity which then monitors the database connection using the following code:
MainActivity
DatabaseReference connectedRef = FirebaseDatabase.getInstance().getReference(".info/connected");
connectedRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot snapshot) {
boolean connected = snapshot.getValue(Boolean.class);
if (connected) {
System.out.println("connected");
} else {
System.out.println("not connected");
}
}
@Override
public void onCancelled(DatabaseError error) {
System.err.println("Listener was cancelled");
}
});
Would anyone know what is causing the app to lose connection? So far the error has been experienced in 2 different projects with 2 auth providers (twitter and facebook) and only after updating to the new Firebase.
回答1:
Firebase fixed the connection issue with the release of 9.0.2. Also for anyone still having trouble, I found the answer on this page very useful. Especially the troubleshoot guide produced by the firebase team for those still experiencing auth token issues after updating to 9.0.2.
来源:https://stackoverflow.com/questions/37462087/losing-connection-with-firebase-database-after-updating-to-new-sdk