mattn / mattn/go-sqlite3

Memory DB with transaction lost on canceled Context due to lack of SessionResetter, Validator

Open
#923 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
9.2k
Forks
1.2k
Avg merge
19m
Merged PRs (30d)
4

Description

If a memory DB has an operation in progress in a transaction with a Context, and that context is canceled, the entire memory DB will be lost.

What?!

When a transaction is opened with a context, a background goroutine is started to roll back the transaction as soon as the context is Done(): https://github.com/golang/go/blob/release-branch.go1.16/src/database/sql/sql.go#L1786

If that rollback fires, it conditionally will close the corresponding connection based on whether the driver implements both driver.SessionResetter and driver.Validator: https://github.com/golang/go/blob/release-branch.go1.16/src/database/sql/sql.go#L1764-L1766

Since this package implements neither of those, any time a transaction against a memory connection is rolled back due to context cancellation, the entire database is lost ... unless you have other connections open and are using shared cache mode I guess. But that combination leads to endless "table is locked" errors and so is oft avoided.

My guess is that implementing these two interfaces would be pretty easy for SQLite?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the transaction cancellation and rollback behavior described in the linked database/sql source, then inspect the driver’s handling of in-memory connections and the SessionResetter and Validator interfaces. Reproduce cancellation during a transaction and verify that the in-memory database remains available afterward, with tests covering the canceled-context case.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sqlite
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.