Skip to content
This repository was archived by the owner on Nov 1, 2018. It is now read-only.
This repository was archived by the owner on Nov 1, 2018. It is now read-only.

Deadlock (eventually times out) inside Serializable transactions #474

@bricelam

Description

@bricelam

Here is some over-simplified code demonstrating the problem.

var connectionString = "Data Source=transations;Mode=Memory;Cache=Shared";
using (var connection1 = new SqliteConnection(connectionString))
using (var connection2 = new SqliteConnection(connectionString))
{
    connection1.Open();
    connection2.Open();

    connection1.ExecuteNonQuery("CREATE TABLE Data (Value); INSERT INTO Data VALUES (0);");

    using (connection1.BeginTransaction())
    using (connection2.BeginTransaction())
    {
        connection1.ExecuteNonQuery("SELECT * FROM Data");
        connection2.ExecuteNonQuery("SELECT * FROM Data");

        // Each command is waiting for the other transaction to complete
        connection1.ExecuteNonQuery("UPDATE Data SET Value = 1");
        connection2.ExecuteNonQuery("UPDATE Data SET Value = 2");
    }
}

In version 1.x, we avoided the deadlock since connection2 couldn't begin the transaction until the one on connection1 completed.

In version 2.0.0, we allow both transactions to begin which eventually leads to the deadlock. Note, one of the commands eventually times out and throws rolling back its transaction unblocking the application.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions