重新连接到Internet后,Firestore无法检索数据 [英] Firestore fails to retrieve data after reconnecting to the Internet

查看:65
本文介绍了重新连接到Internet后,Firestore无法检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将Firestore与Android SDK(11.6.2)结合使用,并且在设备离线并重新连接到Internet时遇到异常.

I'm using Firestore with the Android SDK (11.6.2) and I'm hitting an exception when my device was offline and reconnects to the Internet.

请求文档时,firestore失败,并出现以下任务异常:

When requesting a document, firestore fails with the following task exception :

com.google.firebase.firestore.FirebaseFirestoreException:由于客户端处于离线状态,因此无法获取文档.

com.google.firebase.firestore.FirebaseFirestoreException: Failed to get document because the client is offline.

但是,设备已连接,我可以使用Firestore发出网络请求,然后网络请求成功.此错误不一致,有时在重新连接到Internet后,请求将立即成功.有时,请求一次又一次失败,然后成功,有时在将设备重新连接到Internet一分钟后.

However, the device is connected, I can make network requests beside using Firestore and they succeed. This error is not consistent, sometimes the request will succeed right after reconnecting to the Internet. Sometimes, the request fails again and again, then succeeds, sometimes more than one minute after the device has been reconnected to the Internet.

这是一个产生异常的示例请求:

Here is a sample request that produces the exception:

val docRef = firestore.collection("foo").document("bar")
docRef.get().addOnCompleteListener { task ->
    if (task.isSuccessful) {
        Log.d("FirestoreSourceSet", "Get document success")
    } else {
        Log.e("FirestoreSourceSet", "Get document error", task.exception)
    }
}

我没有使用Firestore的脱机功能,因此FirebaseFirestore实例在第一次使用 setPersistenceEnabled(false)标志初始化:

I'm not using the offline capabilities of Firestore, thus the FirebaseFirestore instance is initialized the first time with the setPersistenceEnabled(false) flag:

val firestoreSettings = FirebaseFirestoreSettings.Builder()
    .setPersistenceEnabled(false)
    .build()

val firestore = FirebaseFirestore.getInstance().apply {
    this.firestoreSettings = firestoreSettings
}

即使设备处于联机状态,为什么Firestore仍会返回此错误?我是否在Firestore配置中缺少可以避免此错误的内容?

Why is Firestore returning this error even though the device is online? Am I missing something in the Firestore configuration that would avoid this error?

我尝试将Firebase升级到11.8.0版本,但是遇到相同的行为.

I tried upgrading Firebase to the 11.8.0 version, but I encounter the same behavior.

以下是在离开飞行模式后尝试与Firestore同步某些数据(从文档获取开始)时的日志:https://pastebin.com/xDMG2Pzj

These are the logs while trying to fetch sync some data with Firestore (which begins with a document fetch) after leaving airplane mode: https://pastebin.com/xDMG2Pzj

在我第一次等待Wifi解决之前,网络在第一个Firestore调用之前已经可用,并使用

The network is already available before the first Firestore call, as I waited for the Wifi to settle, and check it using the ConnectivityManager of Android before proceeding with Firestore.

多次调用是因为每次遇到错误后,我都会使用按钮手动重试,直到成功检索文档为止.

The multiple calls are because I manually retry using a button each time I get the error until the document is successfully retrieved.

日志的第一行是当我转为飞行模式时,它将关闭Firestore的流.

The first line of the log is when I turn the airplane mode one, which closes the stream of Firestore.

Firebase没有公共跟踪程序,但是我使用其报告来报告了此问题工具,然后制作了一个可重现此问题的存储库.

Firebase doesn't have a public tracker, but I reported the issue using their report tool, and made a repo that reproduces the issue.

他们承认该问题,但无法提供预计到达时间,因此我们必须等待:

They acknowledged the issue but could not provide an ETA, so we have to wait:

如果发布此修复程序,我们将在发行说明页面中宣布它.

If we release the fix, we will announce it in our release notes page.

从firestore-core 17.0.4开始,这仍然是一个问题

This is still an issue as of firestore-core 17.0.4

推荐答案

此问题已由Cloud Firestore的17.1.5版修复.

This issue was fixed by the release 17.1.5 of Cloud Firestore.

请参阅官方变更日志 https://firebase.google.com/support/release-notes/android

Cloud Firestore现在可以从不良的网络状态更快地恢复.

Cloud Firestore now recovers more quickly from bad network states.


使用我的18.0.0版复制项目,确实不存在该问题.


Using my reproduction project with the version 18.0.0, the issue is indeed not present.

这篇关于重新连接到Internet后,Firestore无法检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆