Skip to content

SQLite: Use multi-threaded mode by default #22330

Closed as not planned
Closed as not planned

Description

@bricelam

We should investigate using multi-threaded mode by default in Microsoft.Data.Sqlite.

SQLitePCLRaw's e_sqlite3 uses the default SQLITE_THREADSAFE of Serialized.

We don't want to affect other usages of SQLitePCLRaw, so we can't use SQLITE_CONFIG_MULTITHREAD.

We'd need to use SQLITE_OPEN_NOMUTEX when opening the connection.

In this mode, a connection cannot be used simultaneously on different threads, but I believe that is already a de facto limitation of ADO.NET, so we should be fine. We also need to be aware of any limitations this might impose on a connection pool (issue #13837).

This will avoid locks during Open and Execute.

Activity

  1. self-assigned this
    on Aug 31, 2020
  2. added this to the Backlog milestone on Aug 31, 2020
  3. roji commented on Aug 31, 2020

    @roji
    Member

    In this mode, a connection cannot be used simultaneously on different threads, but I believe that is already a de facto limitation of ADO.NET [...]

    Agreed, I'm not aware of any other provider where the same connection instance can be used concurrently... It may be worth considering what happens if the user does do this - a concurrent usage exception here is much better than undefined behavior. Any synchronization here is likely to be very low-overhead because it's error-detection only (i.e. no contention), and reducing contention of global locks during Open/Execute sounds great.

    We also need to be aware of any limitations this might impose on a connection pool

    I think this should be orthogonal - other providers provide pooling while at the same time not supporting concurrent usage of the same instance...

  4. modified the milestones: Backlog, 6.0.0 on Nov 4, 2020
  5. added a commit that references this issue on Dec 8, 2020
    011414c
  6. added a commit that references this issue on Dec 8, 2020
    9594877
  7. added a commit that references this issue on Jan 5, 2021
    b7d5f73
  8. 4 remaining items

  9. removed this from the milestone on Aug 16, 2021
  10. bricelam commented on Aug 16, 2021

    @bricelam
    ContributorAuthor

    Had to revert this since we started seeing AccessViolationException.

    It may be worth investigating further to see if this is an actual SQLite bug or if we can be safer inside object finalizers.

  11. added this to the Backlog milestone on Aug 17, 2021
  12. ajcvickers commented on Oct 26, 2022

    @ajcvickers
    Contributor

    Note from triage: does not seem possible to do this safely.

  13. removed this from the Backlog milestone on Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions