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

Commit failure unhandled, database left in unusable state #366

Closed
kornelski opened this issue Jul 27, 2018 · 1 comment · Fixed by #367
Closed

Commit failure unhandled, database left in unusable state #366

kornelski opened this issue Jul 27, 2018 · 1 comment · Fixed by #367

Comments

@kornelski
Copy link
Contributor

When sqlite is used from multiple processes at the same time, COMMIT may fail with "database is locked" error.

After that happens, all subsequent transactions in rusqlite fail with "cannot start a transaction within a transaction".

I think this is because:

    fn commit_(&mut self) -> Result<()> {
        self.committed = true;
        self.conn.execute_batch("COMMIT")
    }

Sets self.committed = true; without checking whether commit has succeeded, and when COMMIT fails, the transaction remains open — forever.

It should probably be:

    fn commit_(&mut self) -> Result<()> {        
        self.conn.execute_batch("COMMIT")?;
        self.committed = true;
        Ok(())
    }
kornelski added a commit to kornelski/rusqlite that referenced this issue Jul 27, 2018
kornelski added a commit to kornelski/rusqlite that referenced this issue Jul 27, 2018
If transaction can't be automatically committed, roll it back to prevent transaction staying open past the lifetime of the Transaction object

Fixes rusqlite#366
@gwenn
Copy link
Collaborator

gwenn commented Jul 27, 2018

Random thoughts:

  • either use the sqlite3_get_autocommit method and remove the committed flag.
  • or do a rollback when a COMMIT fails.

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 a pull request may close this issue.

2 participants