gpt4 book ai didi

google-cloud-firestore - onSnapshot : FirebaseError: [code=invalid-argument]: transaction closed 中的错误

转载 作者:行者123 更新时间:2023-12-04 09:56:36 25 4
gpt4 key购买 nike

我正在递归加载存储在 Firestore 中的树。这棵树有大约 79 个节点。

我偶尔会收到此错误(大约十分之一的完整树负载)。

编辑:代码:https://github.com/karol-depka/OrYoL

编辑:部署的示例:https://oryol.karoldepka.com/tree (对不起,暂时没有plunker,只有这个)

详情如下。

package.json 中的 Firebase 版本:4.5.0
问题:

我在哪里可以获得比此基本文档更多的信息 https://firebase.google.com/docs/reference/js/firebase.FirebaseError
?

问题的根源是什么以及如何解决?

3VM724:27 Uncaught Error in onSnapshot: Error: transaction closed
at new FirestoreError (error.js:164)
at JsonProtoSerializer.webpackJsonp.../../../../firebase/firestore/remote/serializer.js.JsonProtoSerializer.fromRpcStatus (serializer.js:126)
at JsonProtoSerializer.webpackJsonp.../../../../firebase/firestore/remote/serializer.js.JsonProtoSerializer.fromWatchChange (serializer.js:517)
at PersistentListenStream.webpackJsonp.../../../../firebase/firestore/remote/persistent_stream.js.PersistentListenStream.onMessage (persistent_stream.js:334)
at persistent_stream.js:270
at persistent_stream.js:247
at async_queue.js:81
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:392)
at Object.onInvoke (core.es5.js:3890)
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:391)

编码:
private processNodeEvents(nestLevel: number, snapshot: any, parents, listener: DbTreeListener) {
const serviceThis = this
snapshot.docChanges.forEach(function(change) {
let data = change.doc.data()
if (change.type === 'added') {
const parentsPath = serviceThis.nodesPath(parents)
console.log('node: ', nestLevel, parentsPath, data);
serviceThis.pendingListeners ++
data.node.onSnapshot(targetNodeDoc => {
serviceThis.pendingListeners --
listener.onNodeAdded(
new NodeAddEvent(parentsPath, parentsPath[parentsPath.length - 1], targetNodeDoc, targetNodeDoc.id,
serviceThis.pendingListeners))
console.log('target node:', nestLevel, targetNodeDoc)
console.log('target node title:', nestLevel, targetNodeDoc.data().title)

const subCollection = targetNodeDoc.ref.collection('subNodes')
console.log('subColl:', subCollection)
subCollection.onSnapshot((subSnap: QuerySnapshot) => {
const newParents = parents.slice(0)
newParents.push(targetNodeDoc.ref)
serviceThis.processNodeEvents(nestLevel + 1, subSnap, newParents, listener)
})
})
// console.log('root node ref: ', targetNode);
}
if (change.type === 'modified') {
console.log('Modified city: ', data);
}
if (change.type === 'removed') {
console.log('Removed city: ', data);
}
})
}

编辑:通过多次运行代码发现了另一个错误:
VM3343:27 Uncaught Error in onSnapshot: Error: The referenced transaction has expired or is no longer valid.
at new FirestoreError (error.js:164)
at JsonProtoSerializer.webpackJsonp.../../../../firebase/firestore/remote/serializer.js.JsonProtoSerializer.fromRpcStatus (serializer.js:126)
at JsonProtoSerializer.webpackJsonp.../../../../firebase/firestore/remote/serializer.js.JsonProtoSerializer.fromWatchChange (serializer.js:517)
at PersistentListenStream.webpackJsonp.../../../../firebase/firestore/remote/persistent_stream.js.PersistentListenStream.onMessage (persistent_stream.js:334)
at persistent_stream.js:270
at persistent_stream.js:247
at async_queue.js:81
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:392)
at Object.onInvoke (core.es5.js:3890)
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:391)
window.console.error @ VM3343:27

编辑:将 firebase 更新为 4.6.0 , 问题发生了 3 次:
Uncaught Error in onSnapshot: Error: transaction closed
at new FirestoreError (error.js:149)
at JsonProtoSerializer.webpackJsonp.../../../../@firebase/firestore/dist/esm/src/remote/serializer.js.JsonProtoSerializer.fromRpcStatus (serializer.js:93)
at JsonProtoSerializer.webpackJsonp.../../../../@firebase/firestore/dist/esm/src/remote/serializer.js.JsonProtoSerializer.fromWatchChange (serializer.js:536)
at PersistentListenStream.webpackJsonp.../../../../@firebase/firestore/dist/esm/src/remote/persistent_stream.js.PersistentListenStream.onMessage (persistent_stream.js:309)
at persistent_stream.js:246
at persistent_stream.js:222
at async_queue.js:62
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:392)
at Object.onInvoke (core.es5.js:3890)
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:391)

编辑:即使发生错误,树似乎仍在继续加载。

编辑:错误的另一个版本,带有 code=aborted (升级后 firebase4.6.0 ):
Error in onSnapshot: FirebaseError: [code=aborted]: The referenced transaction has expired or is no longer valid.
/vendor.bundle.js:18588 errHandler()
/vendor.bundle.js:33367
/polyfills.bundle.js:2970 ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask()
/vendor.bundle.js:107276 Object.onInvokeTask()
/polyfills.bundle.js:2969 ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invokeTask()
/polyfills.bundle.js:2737 Zone.webpackJsonp.../../../../zone.js/dist/zone.js.Zone.runTask()
/polyfills.bundle.js:3044 webpackJsonp.../../../../zone.js/dist/zone.js.ZoneTask.invokeTask()
/polyfills.bundle.js:3033 ZoneTask.invoke()

最佳答案

我或多或少是相同的,它在工作和不工作时是随机的。我不使用快照,但 valueChanges

ERROR Error: transaction closed
at new FirestoreError (error.js:149)
at JsonProtoSerializer.webpackJsonp.../../../../@firebase/firestore/dist/esm/src/remote/serializer.js.JsonProtoSerializer.fromRpcStatus (serializer.js:93)
at JsonProtoSerializer.webpackJsonp.../../../../@firebase/firestore/dist/esm/src/remote/serializer.js.JsonProtoSerializer.fromWatchChange (serializer.js:536)
at PersistentListenStream.webpackJsonp.../../../../@firebase/firestore/dist/esm/src/remote/persistent_stream.js.PersistentListenStream.onMessage (persistent_stream.js:309)
at persistent_stream.js:246
at persistent_stream.js:222
at async_queue.js:62
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:392)
at Object.onInvoke (core.es5.js:3890)
at ZoneDelegate.webpackJsonp.../../../../zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:391)

对我来说,正是这种代码的平静引发了错误:
return Observable.forkJoin(entries.map(entry => {
return this.getPick(entry)
}))

条目中的每个条目用于从 firestore 返回一个选择。
  private getPick(entryId: number) {
return this.afs.collection<Pick>('entry/' + entryId + '/event/' + '9/' + 'picks', ref => ref.where('is_captain','==',true))
.valueChanges()

我不是要劫持你的帖子,但我觉得这很重要。如果我将 forkJoin 更改为
Observable.forkJoin(entries.slice(0,20)...

然后它起作用了,所以我想这是某种查询过载。

关于google-cloud-firestore - onSnapshot : FirebaseError: [code=invalid-argument]: transaction closed 中的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46877243/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com