PhoenixmlDb.Core
TransactionTimeoutException
Thrown when a write transaction cannot be acquired within the specified timeout period.
#TransactionTimeoutException
Namespace: PhoenixmlDb.Core
Thrown when a write transaction cannot be acquired within the specified timeout period.
When it's thrown: By IDocumentDatabase.BeginWriteAsync when another write transaction is in progress and does not complete before the timeout expires.
How to handle it: This is a contention signal — the database is busy with another write. Common strategies include:
-
Retry with backoff: Wait briefly and try again, especially for batch operations that can tolerate short delays.
-
Increase the timeout: If the workload involves large transactions, a longer timeout may be appropriate.
-
Reduce write contention: Break large transactions into smaller batches to reduce lock hold time.
The TransactionTimeoutException.Timeout property indicates the timeout that was exceeded.
#Example
try
{
await using var txn = await db.BeginWriteAsync(TimeSpan.FromSeconds(5));
// ... perform writes ...
await txn.CommitAsync();
}
catch (TransactionTimeoutException ex)
{
Console.WriteLine($"Write lock not acquired within {ex.Timeout}. Retrying...");
// Implement retry logic here
}