Skip to content

Comments

Swallow commit() exception in MiniSQLite destructor, improve state check#8

Open
wandernauta wants to merge 1 commit intoberthubert:mainfrom
wandernauta:dtor
Open

Swallow commit() exception in MiniSQLite destructor, improve state check#8
wandernauta wants to merge 1 commit intoberthubert:mainfrom
wandernauta:dtor

Conversation

@wandernauta
Copy link

This makes it so that MiniSQLite's destructor only attempts to commit if a transaction is actually active, and also makes it so that a failure to commit in the destructor is quietly ignored with no exception thrown.

Before, MiniSQLite carried a boolean flag to indicate whether the SQLite database being wrapped was in a transaction, but this flag could diverge from the actual state by...

  • the "begin" query or "commit" query failing
  • calling code mistakenly doing exec("rollback") or exec("commit")
  • automatic rollbacks caused by e.g. disk I/O or disk full errors

In the last case, the error would cause an exception to be thrown, which would trigger stack unwinding, destroying the MiniSQLite. The MiniSQLite destructor, not having noticed the autorollback, would attempt a commit, which would throw another exception, finally reaching std::terminate.

Also adds tests.

This makes it so that MiniSQLite's destructor only attempts to commit if
a transaction is actually active, and also makes it so that a failure to
commit in the destructor is quietly ignored with no exception thrown.

Before, MiniSQLite carried a boolean flag to indicate whether the SQLite
database being wrapped was in a transaction, but this flag could diverge
from the actual state by...

- the "begin" query or "commit" query failing
- calling code mistakenly doing exec("rollback") or exec("commit")
- automatic rollbacks caused by e.g. disk I/O or disk full errors

In the last case, the error would cause an exception to be thrown, which
would trigger stack unwinding, destroying the MiniSQLite. The MiniSQLite
destructor, not having noticed the autorollback, would attempt a commit,
which would throw another exception, finally reaching std::terminate.

Also adds tests.
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.

1 participant