Skip to content

roll back the transaction when its commit fails; update to sqlite-simple 0.4.19.0 - #2

Open
evgeny-simplex wants to merge 12 commits into
simplex-chat:masterfrom
evgeny-simplex:ep/failed-commit-rollback
Open

evgeny-simplex wants to merge 12 commits into
simplex-chat:masterfrom
evgeny-simplex:ep/failed-commit-rollback

Conversation

@evgeny-simplex

Copy link
Copy Markdown

Problem. The transaction functions roll back when the action throws, but not when COMMIT or RELEASE throws. A COMMIT that fails with SQLITE_BUSY keeps the transaction active (https://sqlite.org/lang_transaction.html), so every later BEGIN on the connection fails with "cannot start a transaction within a transaction".

Fix (Database/SQLite/Simple.hs):

  • a failed COMMIT or RELEASE is rolled back, and its error rethrown;
  • the rollback is skipped when no transaction is active, so the original error is kept;
  • outside a transaction, withSavepoint runs as withTransaction (ROLLBACK TO does not end a transaction, https://sqlite.org/lang_savepoint.html).
  • Tests in test/Errors.hs: busy COMMIT and RELEASE through a second connection, a transaction after a failed savepoint, COMMIT's own error rethrown.

Upstream update to nurpax/sqlite-simple master 2b7b708 (0.4.19.0), reviewed against simplexmq and simplex-chat:

  • taken: new query and fold functions (no name clashes: both import qualified or with lists), MonadThrow Ok keeps the exception (unused by SimpleX), date errors include the field text, docs and tests;
  • not taken: the revert of reading numbers into text fields (b8a1f83), which the fork relies on since 2022 and which would fail only at runtime;
  • kept: package name, direct-sqlcipher dependency (pinned to 2330df3), stack.yaml; upstream's CI workflow adapted.

SimpleX no longer calls these transaction functions after simplex-chat/simplexmq#2084; this keeps the library correct and is the basis of a pull request to nurpax/sqlite-simple.

Merge with a merge commit, not a squash, to keep nurpax master in the history for the next upstream update.

@epoberezkin
epoberezkin marked this pull request as ready for review November 19, 2026 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants