[Webkit-unassigned] [Bug 216769] New: Indexed DB transactions outdated immediately after it just created
bugzilla-daemon at webkit.org
bugzilla-daemon at webkit.org
Mon Sep 21 03:00:31 PDT 2020
https://bugs.webkit.org/show_bug.cgi?id=216769
Bug ID: 216769
Summary: Indexed DB transactions outdated immediately after it
just created
Product: WebKit
Version: Safari 13
Hardware: All
OS: All
Status: NEW
Severity: Normal
Priority: P2
Component: New Bugs
Assignee: webkit-unassigned at lists.webkit.org
Reporter: zjwpeter at gmail.com
Reproduction:
Note: idb is a famous library that wrap IndexedDB API into Promise style to make it easier to use.
It does not contains high level abstractions so it is likely not the bug of idb itself.
For reference, this issue is also tracked in the https://github.com/jakearchibald/idb/issues/201
Expected result on Chrome and Firefox:
https://user-images.githubusercontent.com/5390719/93753730-358a2900-fc33-11ea-80a5-b7d4f3eb731e.png
Bad result on Safari:
https://user-images.githubusercontent.com/5390719/93753660-12f81000-fc33-11ea-94c5-7771dab160c2.png
```js
import('https://cdn.skypack.dev/idb@5.0.6/with-async-ittr').then(async (idb) => {
await idb.deleteDB('test')
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
const openDB = (() => {
/** @type {import('idb').IDBPDatabase<unknown>} */
let db = undefined
return async () => {
if (db) return db
if (!db)
db = await idb.openDB('test', 1, {
upgrade(db, oldVersion, newVersion, transaction) {
db.createObjectStore('store')
},
})
db.addEventListener('close', () => (db = undefined))
return db
}
})()
/** @type {import('idb').IDBPTransaction<unknown, ["store"]>} */
let transaction = undefined
const beforeTx = async () => {
try {
await transaction.objectStore('store').openCursor(IDBKeyRange.only('a'))
console.log('The transaction is alive!')
} catch (e) {
console.log('Transaction outdated', e, 'creating new one')
transaction = (await openDB()).transaction('store', 'readwrite')
}
}
await beforeTx()
await transaction.store.add({ a: 1 }, 'a')
console.log('added a')
await beforeTx()
await transaction.store.add({ a: 1 }, 'b')
console.log('added b')
await sleep(120)
await beforeTx()
await transaction.store.add({ a: 1 }, 'c')
console.log('added c')
await sleep(120)
console.log('before call beforeTx')
await beforeTx()
console.log('after call beforeTx')
const cursor = await transaction.store.openCursor(IDBKeyRange.only('a'))
console.log(cursor.value)
const next = await cursor.continue()
console.log(next)
})
```
--
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20200921/dcbec304/attachment-0001.htm>
More information about the webkit-unassigned
mailing list