Issue context:
Have a piece of code that’s trying to add a new document to RavenDB in an NServiceBus message handler.
The code:
partial void HandleImplementation(SomeMessage message)
{
PutDataIntoCache(message.CacheKey, message.Document);
}
void PutDataIntoCache(string key, Document document)
{
using (var documentStore = new DocumentStore { Url = "http://localhost:8084" })
{
documentStore.Initialize();
using (IDocumentSession session = documentStore.OpenSession())
{
using (var tx = new TransactionScope())
{
session.Store(document, key);
session.SaveChanges();
tx.Complete();
}
}
}
}
The error
I'm getting the following error:
Raven.Abstractions.Exceptions.ConcurrencyException: A document with key: 'cache-fncwr10b' is currently created in another transaction
at Raven.Client.Connection.ServerClient.DirectBatch(IEnumerable`1 commandDatas, String operationUrl) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Connection\ServerClient.cs:line 863
at Raven.Client.Connection.ServerClient.<>c__DisplayClass56.<Batch>b__55(String u) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Connection\ServerClient.cs:line 837
at Raven.Client.Connection.ServerClient.TryOperation[T](Func`2 operation, String operationUrl, Boolean avoidThrowing, T& result) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Connection\ServerClient.cs:line 222
at Raven.Client.Connection.ServerClient.ExecuteWithReplication[T](String method, Func`2 operation) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Connection\ServerClient.cs:line 192
at Raven.Client.Connection.ServerClient.Batch(IEnumerable`1 commandDatas) in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Connection\ServerClient.cs:line 837
at Raven.Client.Document.DocumentSession.SaveChanges() in c:\Builds\RavenDB-Stable\Raven.Client.Lightweight\Document\DocumentSession.cs:line 441
at CacheWarmer.Listener.Caching.UpdateCacheEntryProcessor.PutDataIntoCache(String key, ConfgDataModel confgDataModel) in UpdateCacheEntryProcessor.cs
The question
Has anyone run across this? How did you solve it? What could be causing this?
Any helpful comments or tips will be greatly appreciated!
Also, do NOT create a new
DocumentStoreon every call.