Skip to content

TransactionScope timeout does not work #495

@smmansoor

Description

@smmansoor

Summary:

Transaction does not rollback if scope timeout has elapsed.

Detailed description:

Consider the following sample. We declare the TransactionScope with scopeTimeOut.
When execute command and the time is over as specified in scopeTimeout. The transaction aborts but the command does not rollback.


using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TimeSpan(0, 0, 5)))
{
    using (conn1)
    {
        conn.Open();
        NpgsqlCommand cmd = conn.CreateCommand();
        cmd.CommandText = "update test_ts set c2='sssss' where c1=1";
        cmd.ExecuteNonQuery();                                 // the update operation is expected to rollback
        System.Threading.Thread.Sleep(6000);
    }
    scope.Complete();
}

Following is the error message and stack trace.


[Error Message]
The transaction has aborted.

[StackTrace]
   at System.Transactions.TransactionStateAborted.BeginCommit(InternalTransactio
n tx, Boolean asyncCommit, AsyncCallback asyncCallback, Object asyncState)
   at System.Transactions.CommittableTransaction.Commit()
   at System.Transactions.TransactionScope.InternalDispose()
   at System.Transactions.TransactionScope.Dispose()

Following is the patch to fix the above mentioned issue.

https://gist.github.com/smmansoor/d5cd7067bdb6a6d25183#file-transactionscope_timeout_invalid-patch

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions