SaveChanges inside a TransactionScope hangs, and then fails (probably after a timeout)

380 views
Skip to first unread message

Igor Shapiro

unread,
Apr 25, 2011, 10:58:34 AM4/25/11
to ravendb
I wanted to test the behavior of RavenDB with TransactionScopes. It
looks like it fails on the basic scenario. Am I doing something wrong?

Running NUnit 2.5.7, Raven DB Build 322 (latest)

The following exception is thrown by the code below:

System.Runtime.InteropServices.COMException : A resource manager with
the same identifier is already registered with the specified
transaction coordinator. (Exception from HRESULT: 0x8004D102)
at
System.Transactions.Oletx.IDtcProxyShimFactory.CreateResourceManager(Guid
resourceManagerIdentifier, IntPtr managedIdentifier, ref
IResourceManagerShim resourceManagerShim)
at
System.Transactions.Oletx.OletxResourceManager.get_ResourceManagerShim()
at
System.Transactions.Oletx.OletxResourceManager.EnlistDurable(OletxTransaction
oletxTransaction, Boolean canDoSinglePhase,
IEnlistmentNotificationInternal enlistmentNotification,
EnlistmentOptions enlistmentOptions)
at System.Transactions.Oletx.OletxTransaction.EnlistDurable(Guid
resourceManagerIdentifier, ISinglePhaseNotificationInternal
singlePhaseNotification, Boolean canDoSinglePhase, EnlistmentOptions
enlistmentOptions)
at
System.Transactions.TransactionStatePromotedBase.EnlistDurable(InternalTransaction
tx, Guid resourceManagerIdentifier, IEnlistmentNotification
enlistmentNotification, EnlistmentOptions enlistmentOptions,
Transaction atomicTransaction)
at
System.Transactions.EnlistableStates.EnlistDurable(InternalTransaction
tx, Guid resourceManagerIdentifier, IEnlistmentNotification
enlistmentNotification, EnlistmentOptions enlistmentOptions,
Transaction atomicTransaction)
at System.Transactions.Transaction.EnlistDurable(Guid
resourceManagerIdentifier, IEnlistmentNotification
enlistmentNotification, EnlistmentOptions enlistmentOptions)
at
Raven.Client.Document.InMemoryDocumentSessionOperations.TryEnlistInAmbientTransaction()
in c:\Builds\raven\Raven.Client.Lightweight\Document
\InMemoryDocumentSessionOperations.cs: line 737
at
Raven.Client.Document.InMemoryDocumentSessionOperations.PrepareForSaveChanges()
in c:\Builds\raven\Raven.Client.Lightweight\Document
\InMemoryDocumentSessionOperations.cs: line 671
at Raven.Client.Document.DocumentSession.SaveChanges() in c:\Builds
\raven\Raven.Client.Lightweight\Document\DocumentSession.cs: line 320
at Framework.Tests.RavenDBUseCaseTests.ReproduceTransactionFailure()
in RavenDBUseCaseTests.cs: line 45

--- THE CODE ---
public class TestUser {
public string Id { get; set; }

public TestUser() {
Id = "users/";
}
}

[Test]
public void ReproduceTransactionFailure() {
using (var scope = new TransactionScope())
{
using (var session =
Infrastructure.Instance.ApplicationDocumentStore.OpenSession())
{
TestUser testUser = new TestUser();
session.Store(testUser);

session.SaveChanges();

scope.Complete();
}
}

}

Igor Shapiro

unread,
Apr 25, 2011, 4:14:28 PM4/25/11
to ravendb
I figured it out. Generated a new ResourceManagerId when creating the
Document Store.

Ayende Rahien

unread,
Apr 27, 2011, 7:45:06 AM4/27/11
to rav...@googlegroups.com
Can you explain a bit more about this, what do you mean happened here?

Igor Shapiro

unread,
Apr 27, 2011, 7:54:46 AM4/27/11
to ravendb
I suspect that the following caused the exception:

I have a RavenDB server hosted by IIS. That's one instance.
For unit tests I create an embedded in-memory instance of RavenDB
(which is VERY convenient).

From what I saw in the source code, by default raven assigns a hard-
coded guid for the ResourceManagerId property (which then used by the
DTC). So the IIS and embedded server both try to register with the
same ResourceManagerId (the hardcoded one).
I've changed this Id to be automatically generated on IDocumentStorage
creation and everything now works fine.

Predictable :)

The ResourceManagerId issue even mentioned somewhere in the
documentation.

Ayende Rahien

unread,
Apr 27, 2011, 8:11:42 AM4/27/11
to rav...@googlegroups.com
Good point, I changed it to happen automatically
Reply all
Reply to author
Forward
0 new messages