Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to execute 'objectStore' on 'IDBTransaction': The transaction has finished #1564

Open
jawalkwan opened this issue May 8, 2022 · 18 comments
Labels

Comments

@jawalkwan
Copy link

code: 11
message: "Failed to execute 'objectStore' on 'IDBTransaction': The transaction has finished."
name: "InvalidStateError"

my code is simple:
return await this.table.update(id, { examineDate: data.examineDate })
but,it return error notice like that ↑,I found so many answers from google and github and stackoverflow but no one useful
help me please,it's very urgent, thx
@dfahlander 🙏

@dfahlander
Copy link
Collaborator

This happens when you execute a transaction and await non-Dexie calls within it.

await db.transaction('rw', db.myTable, async () => {
  await fetch('https://xyz.org/...'); // Here's a problem: awaiting non-dexie call within a transaction
  return await this.table.update(id, { examineDate: data.examineDate });
});

This is also described here

If your function is not executing within a transaction, the case can also be that your caller has the transaction block and calls your function within it after doing the non-dexie work.

Let me know if that was the case and what version of dexie you are using.

@jawalkwan
Copy link
Author

alright, I installed latest version dexie in my project
my code in function just has one line ,like this:

async update(data: any) {
return await this.table.update(id, { examineDate: data.examineDate })
}

haven't transaction around of them. I ever tried to write the transaction around of this codes, but didn't work

@dfahlander
Copy link
Collaborator

Are you using a very old browser or Internet Explorer, Legacy Edge or very old version of some other browser?

@dfahlander
Copy link
Collaborator

These type of problems occur on very old browsers - but also when using IndexedDBShim or possibly also fakeIndexedDB instead of using the native IndexedDB in the browser.

One workaround is to transpile the application code to <= ES2016 to get rid of the ES2017 async/await keywords which in those environments are incompatible with IndexedDB transactions.

@jawalkwan
Copy link
Author

I using the latest version electron, it included chromium version about 100.x, so I don't think about it's reason for browser's version. My frontend platform using vue3+vite,it would translate the typescript code to es2015 and support async/await better, I also not doubt the trouble is from code's version
maybe i was wrong, if you need, I can make and share a demo with the problem to you for position the problem

@jawalkwan
Copy link
Author

btw, did you have obstacle for my english? my grammar was too terrible😂

@dfahlander
Copy link
Collaborator

Check if IndexedDBShim is included. Try remove it. If you'd still need IndexedDBShim, make sure to transpile the code to ES2016 or ES2015.

No problem with your English :)

@jawalkwan
Copy link
Author

Ok, I will try it later and give the feedback to you when it still don't work
Thank you so much!😉

@licao404
Copy link

licao404 commented May 18, 2022

I had a similar problem, Sentry sounds the alarm:
"InvalidStateError: Failed to execute 'abort' on 'IDBTransaction': The transaction has finished."

my environment: Electron Version:13.1.7.
my Dexie.js version: 3.0.1.

help me please,it's very urgent, thx
@dfahlander

@jawalkwan
Copy link
Author

@licao404 我按大佬的方法试了还是没啥用,现在已经转sqlite了,因为项目比较急,没时间研究,所以兄弟你要不要也先用sqlite试试,这个库好像在electron下有点纠结😂

@licao404
Copy link

@delayhsiao 好像也不是这个库独有的问题,这个库你用的是哪个版本,我看其他indexdb库下也有类似的issues,评论基本上说是浏览器内核的bug。难搞啊

@jawalkwan
Copy link
Author

jawalkwan commented May 18, 2022

@delayhsiao 好像也不是这个库独有的问题,这个库你用的是哪个版本,我看其他indexdb库下也有类似的issues,评论基本上说是浏览器内核的bug。难搞啊

我用的最新版,反正大家都在吹indexeddb,但是我发现这玩意儿就跟h5早期状态一样,各家都有不同的支持状态。所以我现在转了sqlite3,用得很流畅,性能什么的,反正单机给个loading让它转就完事儿了

@licao404
Copy link

licao404 commented May 18, 2022

I had a similar problem, Sentry sounds the alarm: "InvalidStateError: Failed to execute 'abort' on 'IDBTransaction': The transaction has finished."

my environment: Electron Version:13.1.7. my Dexie.js version: 3.0.1.

help me please,it's very urgent, thx @dfahlander

I don't know if it's similar to these issues :

@dfahlander

@dfahlander
Copy link
Collaborator

dfahlander commented May 18, 2022

Can you confirm whether IndexedDBShim is being used or not? If IndexedDBShim is used, you must either avoid using async/await or transpile your code to ES2016 (or ES2015 or ES5) in order to avoid native async/await as it will not work with IndexedDBShim.

In order to use Dexie in node (Electron main process is a node process), IndexedDBShim can be used as an adapter between the IndexedDB API and SQLite, but IndexedDBShim has the same issues as browsers used to have historically - it won't keep transactions alive between micro ticks.

@ArcherGu
Copy link

same problem and no solution 😢

@superocky
Copy link

Using the put method and abandoning the update method can solve the problem. Currently I am using this solution

@dfahlander
Copy link
Collaborator

@superocky & @ArcherGu Are you in a browser platform, Electron or is this happening in node based unit tests (using IndexedDBShim or fakeIndexedDB to run tests in node)? What's your user agent & version? It would also help if someone could create a repro of this problem or else pin point the platforms where this happens.

@the-didi
Copy link

some problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants