生产环境中的 FirebaseRemoteConfigClientException (Android)
FirebaseRemoteConfigClientException on production (Android)
到目前为止我做了什么...
我在工作线程中使用 Tasks.await
blocking firebase 调用机制来避免回调。
我正在使用工作线程 (JobIntentService) 进行一些初始化。 JobIntentService 在应用程序打开时启动并仅运行一次。下面是我的工作线程代码
if (isDeviceConnectedToInternet()) {
Tasks.await(FirebaseConfigHelper.getRemoteConfig().fetchAndActivate()); //error here
initFirebaseConfigVariables();
// other codes
}
//FirebaseConfigHelper.java
public static FirebaseRemoteConfig getRemoteConfig() {
FirebaseRemoteConfig mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
mFirebaseRemoteConfig.setDefaultsAsync(R.xml.remote_config_defaults);
return mFirebaseRemoteConfig;
}
我正在使用
implementation 'com.google.firebase:firebase-config:19.0.4'
关于错误
它在测试设备中运行良好。我在 Firebase Test Lab 中测试了另外 15 台设备。完全没有问题。但是当我发布到生产环境时,这个错误发生在一些特定的 Mi 和 Samsung 设备上。
错误日志
我只能得到这个日志,因为生产中发生了错误
java.util.concurrent.ExecutionException:
com.google.firebase.remoteconfig.FirebaseRemoteConfigClientException:
The client had an error while calling the backend! at
com.google.android.gms.tasks.Tasks.zzb(Unknown Source:61) at
com.google.android.gms.tasks.Tasks.await(Unknown Source:23) at
com.maju.myapp.service.SyncWithFirebaseJobIntentService.syncWithFirebaseConfig(SyncWithFirebaseJobIntentService.java:207) at
com.maju.myapp.service.SyncWithFirebaseJobIntentService.onHandleWork(SyncWithFirebaseJobIntentService.java:55) at
androidx.core.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:392) at
androidx.core.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:383) at
android.os.AsyncTask.call(AsyncTask.java:378) at
java.util.concurrent.FutureTask.run(FutureTask.java:266) at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at
java.lang.Thread.run(Thread.java:919)Caused by:
com.google.firebase.remoteconfig.FirebaseRemoteConfigClientException:
The client had an error while calling the backend! at
com.google.firebase.remoteconfig.internal.ConfigFetchHttpClient.fetch(com.google.firebase:firebase-config@@19.0.4:194) at
com.google.firebase.remoteconfig.internal.ConfigFetchHandler.fetchFromBackend(com.google.firebase:firebase-config@@19.0.4:278) at
com.google.firebase.remoteconfig.internal.ConfigFetchHandler.fetchFromBackendAndCacheResponse(com.google.firebase:firebase-config@@19.0.4:251) at
com.google.firebase.remoteconfig.internal.ConfigFetchHandler.fetchIfCacheExpiredAndNotThrottled(com.google.firebase:firebase-config@@19.0.4:191) at
com.google.firebase.remoteconfig.internal.ConfigFetchHandler.lambda$fetch[=13=](com.google.firebase:firebase-config@@19.0.4:160) at
com.google.firebase.remoteconfig.internal.ConfigFetchHandler$$Lambda.then(Unknown
Source:4) at com.google.android.gms.tasks.zzf.run(Unknown
Source:2) ... 3 moreCaused by: java.net.ConnectException: Failed to
connect to
firebaseremoteconfig.googleapis.com/2404:6800:4007:809::200a:443 at
com.android.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:147) at
com.android.okhttp.internal.io.RealConnection.connect(RealConnection.java:116) at
com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:186) at
com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:128) at
com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:97) at
com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:289) at
com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:232) at
com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:465) at
com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:131) at
com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:262) at
com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:219) at
com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:30) at
com.google.firebase.remoteconfig.internal.ConfigFetchHttpClient.setFetchRequestBody(com.google.firebase:firebase-config@@19.0.4:321) at
com.google.firebase.remoteconfig.internal.ConfigFetchHttpClient.fetch(com.google.firebase:firebase-config@@19.0.4:182) ...
9 more
- 为什么会这样?
- 如何避免?
(回调让代码变得丑陋和混乱,为了让代码更干净我更喜欢Tasks.await)
我就此问题联系了 Firebase 支持
他们说
This happens if the connection of the device user had an issue as our
SDK tried to call the fetch of data, and it would cause “The client
had an error while calling the backend!” error. With that, it looks
like you’re doing the right thing on validating the connectivity on
your recent updates before you fetch the remote config data. You can
check our implementation here that you could visualize our call
that would trigger this issue.
You could use the Android network debugger to simulate the
network calls, so you could catch your handling mechanism to ensure
that your actual device has a proper connectivity on doing the fetch.
所以问题可能出在设备的网络连接上。我检查最近更新中的网络连接。但我仍然在某些设备上收到此错误。原因可能是设备当时的互联网连接质量差(@Tash Pemhiwa 在评论中建议)
到目前为止我做了什么...
我在工作线程中使用 Tasks.await
blocking firebase 调用机制来避免回调。
我正在使用工作线程 (JobIntentService) 进行一些初始化。 JobIntentService 在应用程序打开时启动并仅运行一次。下面是我的工作线程代码
if (isDeviceConnectedToInternet()) {
Tasks.await(FirebaseConfigHelper.getRemoteConfig().fetchAndActivate()); //error here
initFirebaseConfigVariables();
// other codes
}
//FirebaseConfigHelper.java
public static FirebaseRemoteConfig getRemoteConfig() {
FirebaseRemoteConfig mFirebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
mFirebaseRemoteConfig.setDefaultsAsync(R.xml.remote_config_defaults);
return mFirebaseRemoteConfig;
}
我正在使用
implementation 'com.google.firebase:firebase-config:19.0.4'
关于错误
它在测试设备中运行良好。我在 Firebase Test Lab 中测试了另外 15 台设备。完全没有问题。但是当我发布到生产环境时,这个错误发生在一些特定的 Mi 和 Samsung 设备上。
错误日志
我只能得到这个日志,因为生产中发生了错误
java.util.concurrent.ExecutionException:
com.google.firebase.remoteconfig.FirebaseRemoteConfigClientException:
The client had an error while calling the backend! at
com.google.android.gms.tasks.Tasks.zzb(Unknown Source:61) at
com.google.android.gms.tasks.Tasks.await(Unknown Source:23) at
com.maju.myapp.service.SyncWithFirebaseJobIntentService.syncWithFirebaseConfig(SyncWithFirebaseJobIntentService.java:207) at
com.maju.myapp.service.SyncWithFirebaseJobIntentService.onHandleWork(SyncWithFirebaseJobIntentService.java:55) at
androidx.core.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:392) at
androidx.core.app.JobIntentService$CommandProcessor.doInBackground(JobIntentService.java:383) at
android.os.AsyncTask.call(AsyncTask.java:378) at
java.util.concurrent.FutureTask.run(FutureTask.java:266) at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at
java.lang.Thread.run(Thread.java:919)Caused by:
com.google.firebase.remoteconfig.FirebaseRemoteConfigClientException:
The client had an error while calling the backend! at
com.google.firebase.remoteconfig.internal.ConfigFetchHttpClient.fetch(com.google.firebase:firebase-config@@19.0.4:194) at
com.google.firebase.remoteconfig.internal.ConfigFetchHandler.fetchFromBackend(com.google.firebase:firebase-config@@19.0.4:278) at
com.google.firebase.remoteconfig.internal.ConfigFetchHandler.fetchFromBackendAndCacheResponse(com.google.firebase:firebase-config@@19.0.4:251) at
com.google.firebase.remoteconfig.internal.ConfigFetchHandler.fetchIfCacheExpiredAndNotThrottled(com.google.firebase:firebase-config@@19.0.4:191) at
com.google.firebase.remoteconfig.internal.ConfigFetchHandler.lambda$fetch[=13=](com.google.firebase:firebase-config@@19.0.4:160) at
com.google.firebase.remoteconfig.internal.ConfigFetchHandler$$Lambda.then(Unknown
Source:4) at com.google.android.gms.tasks.zzf.run(Unknown
Source:2) ... 3 moreCaused by: java.net.ConnectException: Failed to
connect to
firebaseremoteconfig.googleapis.com/2404:6800:4007:809::200a:443 at
com.android.okhttp.internal.io.RealConnection.connectSocket(RealConnection.java:147) at
com.android.okhttp.internal.io.RealConnection.connect(RealConnection.java:116) at
com.android.okhttp.internal.http.StreamAllocation.findConnection(StreamAllocation.java:186) at
com.android.okhttp.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:128) at
com.android.okhttp.internal.http.StreamAllocation.newStream(StreamAllocation.java:97) at
com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:289) at
com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:232) at
com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:465) at
com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:131) at
com.android.okhttp.internal.huc.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:262) at
com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getOutputStream(DelegatingHttpsURLConnection.java:219) at
com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:30) at
com.google.firebase.remoteconfig.internal.ConfigFetchHttpClient.setFetchRequestBody(com.google.firebase:firebase-config@@19.0.4:321) at
com.google.firebase.remoteconfig.internal.ConfigFetchHttpClient.fetch(com.google.firebase:firebase-config@@19.0.4:182) ...
9 more
- 为什么会这样?
- 如何避免?
(回调让代码变得丑陋和混乱,为了让代码更干净我更喜欢Tasks.await)
我就此问题联系了 Firebase 支持
他们说
This happens if the connection of the device user had an issue as our SDK tried to call the fetch of data, and it would cause “The client had an error while calling the backend!” error. With that, it looks like you’re doing the right thing on validating the connectivity on your recent updates before you fetch the remote config data. You can check our implementation here that you could visualize our call that would trigger this issue.
You could use the Android network debugger to simulate the network calls, so you could catch your handling mechanism to ensure that your actual device has a proper connectivity on doing the fetch.
所以问题可能出在设备的网络连接上。我检查最近更新中的网络连接。但我仍然在某些设备上收到此错误。原因可能是设备当时的互联网连接质量差(@Tash Pemhiwa 在评论中建议)