我们正在构建一个应用程序,在 Firefox 上广泛使用 IndexedDB 来存储离线数据。
这在大多数情况下运行良好,但偶尔会失败并出现如下错误:
Exception... "The operation failed because the requested database object could
not be found. For example, an object store did not exist but was being opened."
code: "3" nsresult: "0x80660003 (NS_ERROR_DOM_INDEXEDDB_NOT_FOUND_ERR)"
它似乎在代码的各个地方都失败了;这是罪魁祸首之一:
_writePage: (storeName, startIndex, endIndex, binder) ->
writeTransaction = @connection.transaction([storeName], @idbTransaction.READ_WRITE)
store = writeTransaction.objectStore(storeName)
for index in [startIndex...endIndex] when (item = binder.list[index])?
writeRequest = store.put(item)
writeRequest.onerror = binder.failCallback()
writeRequest.onsuccess = binder.successCallback()
if endIndex >= binder.list.length
binder.finishedRegisteringCallbacks()
return
setTimeout((=> @_writePage(storeName, endIndex, endIndex + @WRITE_EACH_PAGE_SIZE, binder)), @WRITE_EACH_PAGE_DELAY)
null
令我困惑的是,在通常有效的自动化测试期间,故障很少发生(我们每数百次执行都会看到其中一个故障)。
值得一提的是,我们也存储了大量数据,大约为数百兆字节。结果证明自动化测试只存储几兆字节,所以这不是大小问题。
有没有其他人经历过(或者更好的是,经历过并修复过!)这个问题?