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

SQLjs 'cannot commit - no transaction is active' #9100

Closed
Ainias opened this issue Jun 12, 2022 · 1 comment · Fixed by #9234 · May be fixed by antz-snyk1/gradle-npm-monorepo-example#5
Closed

SQLjs 'cannot commit - no transaction is active' #9100

Ainias opened this issue Jun 12, 2022 · 1 comment · Fixed by #9234 · May be fixed by antz-snyk1/gradle-npm-monorepo-example#5

Comments

@Ainias
Copy link

Ainias commented Jun 12, 2022

Issue Description

When autosave is used with sqljs and localforage, sometimes there is an error with the message 'cannot commit - no transaction is active. As far as I can tell, it happens when two or more write-requests are made at the same time. Both start, then the first one ends, the autosave is called. The autosave exports the sqljs-database, which closes the transaction silently. Then the second one ends and tries to close the connection, which is not open anymore. Therefore the error is thrown.
Potentially can this resolve in an unwanted state. If I try to save A & B in separate repositories and B has a dependency C, which must also be saved, then it can happen, that A & B are saved, then the DB is exported, tries to save C, but there is an error in C, such that it tries to rollback the transaction containing B & C. But there is no transaction anymore, which means that the changes in B are saved, but not the one in C and therefore the data is not correct.

Expected Behavior

Call autosave only when no transaction is active in order to not run into errors

Actual Behavior

Steps to Reproduce

My Environment

Dependency Version
Operating System
Browser Brave/Chrome
Typescript version 4.6.3
TypeORM version 0.3.5
sql.js 1.7.0
localforage 1.10.0

Relevant Database Driver(s)

DB Type Reproducible
aurora-mysql no
aurora-postgres no
better-sqlite3 no
cockroachdb no
cordova no
expo no
mongodb no
mysql no
nativescript no
oracle no
postgres no
react-native no
sap no
spanner no
sqlite no
sqlite-abstract no
sqljs yes
sqlserver no

Are you willing to resolve this issue by submitting a Pull Request?

  • ✅ Yes, I have the time, and I know how to start.
  • ✖️ Yes, I have the time, but I don't know how to start. I would need guidance.
  • ✖️ No, I don’t have the time, but I can support (using donations) development.
  • ✖️ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.
@BARNZ
Copy link

BARNZ commented Jun 15, 2022

Running into the same problem as well ever since upgrading to the latest version of TypeORM.

Triggered in my case by simply calling await Entity.save(...) when using sql.js driver with autosave as mentioned above.

image

Obiwan1995 added a commit to Obiwan1995/typeorm that referenced this issue Jul 22, 2022
pleerock pushed a commit that referenced this issue Sep 19, 2022
* fix: fix "Cannot commit, no transaction is active" error in sql.js

Closes: #9100

* Flush database only if transaction is done

Co-authored-by: Brice Miclo <brice.miclo@socomec.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment