Skip to content

Commit b82cfc3

Browse files
committed
Handle transaction abortion in finalizer (#301)
1 parent a3e0f54 commit b82cfc3

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

DuckDB.NET.Data/DuckDBTransaction.cs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,23 @@ private void FinishTransaction(string finalizer)
3838
throw new InvalidOperationException("Transaction has already been finished.");
3939
}
4040

41-
connection.ExecuteNonQuery(finalizer);
42-
connection.Transaction = null;
43-
finished = true;
41+
try
42+
{
43+
connection.ExecuteNonQuery(finalizer);
44+
connection.Transaction = null;
45+
finished = true;
46+
}
47+
// If something goes wrong with the transaction, to match the
48+
// transaction's internal duckdb state it should still be considered
49+
// finished and should no longer be used
50+
catch (DuckDBException ex) when (ex.ErrorType == Native.DuckDBErrorType.Transaction)
51+
{
52+
connection.Transaction = null;
53+
finished = true;
54+
throw;
55+
}
4456
}
45-
46-
57+
4758
protected override void Dispose(bool disposing)
4859
{
4960
base.Dispose(disposing);
@@ -53,4 +64,4 @@ protected override void Dispose(bool disposing)
5364
Rollback();
5465
}
5566
}
56-
}
67+
}

0 commit comments

Comments
 (0)