yesodweb / yesodweb/persistent

SQLite queries are uninterruptible

Open
#1,597 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Haskell
Stars
486
Forks
306
PR merge metrics
No merged PRs in 30d

Description

I think that when a SQLite backend is being accessed, queries are not killable by async exceptions (because, generally, FFI is not interruptible). This means that e.g. WAI timeout middleware is ineffective for a sqlite-backed web server.

SQLite provides a means of interrupting a query:

void sqlite3_interrupt(sqlite3*);
int sqlite3_is_interrupted(sqlite3*);

and some precedent of using this in Haskell can be find in direct-sqlite:

interrupt :: Database -> IO ()
interruptibly :: Database -> IO a -> IO a

... where I believe all three of these are equivalent:

  • Database in Database.SQLite3 in the direct-sqlite package
  • Connection in Database.Sqlite.Internal in the persistent-sqlite package
  • sqlite3* in the SQLite C library

I'm about to attempt to mimic what interruptibly does to make long-running queries killable in my own application. I thought I should also inquire here:

  • Does this explanation and solution all make sense?
  • Would there be any interest in incorporating this solution into the persistent-sqlite package? I think running queries interruptibly should be the default behavior. I would be happy to submit a pull request.

I am not sure if there is an obvious place to insert a solution, but at the very least the persistent-sqlite package could offer documentation on the issue and some utilities for making the interrupt call.

Contributor guide

Open the contributing guide

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 by reading the persistent-sqlite package's Database.Sqlite.Internal connection handling and the direct-sqlite Database.SQLite3 interrupt and interruptibly APIs. Determine where query execution and async-exception handling are defined, then clarify whether the intended result is a default interruptible behavior, public utilities, documentation, or some combination. Done should include an agreed API and coverage for long-running SQLite queries.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell, sqlite
Domain
database
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.