"Unable to delete file" error being thrown in RavenDB when trying to start multiple endpoints at once
When I try to start multiple (between 5 and 10) NServiceBus hosts at one time, I receive the error shown below in some endpoints:
2012-11-20 13:32:05,044 [1] FATAL - (null) - NServiceBus.Hosting.GenericHost - System.AggregateException: One or more errors occurred. ---> System.IO.IsolatedStorage.IsolatedStorageException: Unable to delete file. at System.IO.IsolatedStorage.IsolatedStorageFile.DeleteFile(String file) at Raven.Client.Document.DTC.PendingTransactionRecovery.Execute(IDatabaseCommands commands) in c:\Work\ravendb-1.0\Raven.Client.Lightweight\Document\DTC\PendingTransactionRecovery.cs:line 73 --- End of inner exception stack trace --- at Raven.Client.Document.DTC.PendingTransactionRecovery.Execute(IDatabaseCommands commands) in c:\Work\ravendb-1.0\Raven.Client.Lightweight\Document\DTC\PendingTransactionRecovery.cs:line 81 at Raven.Client.Document.DocumentStore.RecoverPendingTransactions() in c:\Work\ravendb-1.0\Raven.Client.Lightweight\Document\DocumentStore.cs:line 410 at Raven.Client.Document.DocumentStore.Initialize() in c:\Work\ravendb-1.0\Raven.Client.Lightweight\Document\DocumentStore.cs:line 402 at NServiceBus.ConfigureRavenPersistence.EnsureDatabaseExists(DocumentStore store) in c:\TeamCity\buildAgent\work\nsb.master_1\src\impl\Persistence\RavenPersistence\NServiceBus.Persistence.Raven\Config\ConfigureRavenPersistence.cs:line 186 at NServiceBus.ConfigureRavenPersistence.RavenPersistence(Configure config, IDocumentStore store) in c:\TeamCity\buildAgent\work\nsb.master_1\src\impl\Persistence\RavenPersistence\NServiceBus.Persistence.Raven\Config\ConfigureRavenPersistence.cs:line 150 at NServiceBus.ConfigureRavenPersistence.RavenPersistence(Configure config) in c:\TeamCity\buildAgent\work\nsb.master_1\src\impl\Persistence\RavenPersistence\NServiceBus.Persistence.Raven\Config\ConfigureRavenPersistence.cs:line 54 at NServiceBus.Hosting.Windows.Profiles.Handlers.ProductionProfileHandler.NServiceBus.Hosting.Profiles.IHandleProfile.ProfileActivated() in c:\TeamCity\buildAgent\work\nsb.master_1\src\hosting\NServiceBus.Hosting.Windows\Profiles\Handlers\ProductionProfileHandler.cs:line 13 at NServiceBus.Hosting.Profiles.ProfileManager.
b__1c(IHandleProfile hp) in c:\TeamCity\buildAgent\work\nsb.master_1\src\hosting\NServiceBus.Hosting\Profiles\ProfileManager.cs:line 143 at System.Collections.Generic.List 1.ForEach(Action1 action) at NServiceBus.Hosting.Profiles.ProfileManager.ActivateProfileHandlers() in c:\TeamCity\buildAgent\work\nsb.master_1\src\hosting\NServiceBus.Hosting\Profiles\ProfileManager.cs:line 144 at NServiceBus.Hosting.Profiles.ProfileActivator.Run() in c:\TeamCity\buildAgent\work\nsb.master_1\src\hosting\NServiceBus.Hosting\Profiles\ProfileActivator.cs:line 20 at NServiceBus.Configure.b__c(Type t) in c:\TeamCity\buildAgent\work\nsb.master_1\src\config\NServiceBus.Config\Configure.cs:line 296 at System.Collections.Generic.List 1.ForEach(Action1 action) at NServiceBus.Configure.ForAllTypes[T](Action`1 action) in c:\TeamCity\buildAgent\work\nsb.master_1\src\config\NServiceBus.Config\Configure.cs:line 317 at NServiceBus.Configure.Initialize() in c:\TeamCity\buildAgent\work\nsb.master_1\src\config\NServiceBus.Config\Configure.cs:line 299 at NServiceBus.Configure.CreateBus() in c:\TeamCity\buildAgent\work\nsb.master_1\src\config\NServiceBus.Config\Configure.cs:line 263 at NServiceBus.Hosting.GenericHost.Start() in c:\TeamCity\buildAgent\work\nsb.master_1\src\hosting\NServiceBus.Hosting\GenericHost.cs:line 30 ---> (Inner Exception #0) System.IO.IsolatedStorage.IsolatedStorageException: Unable to delete file. at System.IO.IsolatedStorage.IsolatedStorageFile.DeleteFile(String file) at Raven.Client.Document.DTC.PendingTransactionRecovery.Execute(IDatabaseCommands commands) in c:\Work\ravendb-1.0\Raven.Client.Lightweight\Document\DTC\PendingTransactionRecovery.cs:line 73<---
I am starting the endpoints by debugging inside Visual Studio 2012. The error does not seem to occur if I just start a single endpoint at a time.
From looking at the stack trace, the problem appears to be related to pending/incomple DTC transactions. Here is an excerpt of the log file from RavenDB that seems like it is relevant:
2012-11-20 13:39:21.8550,Raven.Storage.Esent.StorageActions.DocumentStorageActions,Debug,"Attachment with key 'transactions/recoveryInformation/b89a4cd0-0906-4001-8232-9ec994f4f0b9' was not found, and considered deleted", 2012-11-20 13:39:21.8550,Raven.Database.Indexing.WorkContext,Debug,Incremented work counter to 2 because: ROLLBACK b89a4cd0-0906-4001-8232-9ec994f4f0b9, 2012-11-20 13:39:21.8550,Raven.Database.Indexing.WorkContext,Debug,"No work was found, workerWorkCounter: 2, for: IndexingExecuter, will wait for additional work", 2012-11-20 13:39:21.8670,Raven.Database.Indexing.WorkContext,Debug,"No work was found, workerWorkCounter: 2, for: ReducingExecuter, will wait for additional work", 2012-11-20 13:39:21.8670,Raven.Database.Server.HttpServer,Debug,Request # 34: POST - 19 ms - MyHandler - 200 - /transaction/rollback?tx=b89a4cd0-0906-4001-8232-9ec994f4f0b9,
Note the last entry indicates that a rollback is being attempted on the "MyHandler" database. "MyHandler" is the name of the endpoint that received the "unable to delete file" exception.
I forgot to mention that I experienced this error on v3.3.2. I will try v3.3 to see if the problem exists on that version.
I've just confirmed that the same problem exists in NServiceBus v3.3.0
We upgraded ravendb in 3.3.0, any chance you could try 3.3.8?(uses the 960 client)
Sent from my iPhone
On 20 nov 2012, at 20:26, Dan Bishop [email protected] wrote:
I've just confirmed that the same problem exists in NServiceBus v3.3.0
— Reply to this email directly or view it on GitHubhttps://github.com/NServiceBus/NServiceBus/issues/757#issuecomment-10568926.
I assume you mean to try using 3.2.8 (not 3.3.8)? I was previously using 3.2.8, but I want to upgrade to 3.3.x so that I can make use of the Namespace mapping feature.
Yes, 3.2.8. Seems like the bug wa introduced in raven client 980
Sent from my iPhone
On 20 nov 2012, at 20:37, Dan Bishop [email protected] wrote:
I assume you mean to try using 3.2.8 (not 3.3.8)? I was previously using 3.2.8, but I want to upgrade to 3.3.x so that I can make use of the Namespace mapping feature.
— Reply to this email directly or view it on GitHubhttps://github.com/NServiceBus/NServiceBus/issues/757#issuecomment-10569391.
According to Oren's comment (from today) on the RavenDB forums, RavenDB will be modified to account for the "Unable to delete file" error: https://groups.google.com/forum/?fromgroups=#!topic/ravendb/b9LC93MRVc4
Depending on what the scope of the change in RavenDB is, it would be great to see this considered for a patch release to NServiceBus, as the problem is a fairly significant block if you are trying to work with even a few handlers.
Yes, definitely this would be a patch release
Oren has commited a fix, I'll try to build it and create a 3.3.3 unstable that you can test Dan - https://github.com/ayende/ravendb/commit/9bc3fd31ed6623d5e43e5dafd0f7c4313b7e12c1
Excellent, let me know when its available and I can test it shortly thereafter.
I've been doing some debugging on this issue, and I'm seeing that RavenDB is encountering the following error while starting up an endpoint:
A resource manager with the same identifier is already registered with the specified transaction coordinator
It is the NServiceBus database where RavenDB is encountering this error (this is visible by checking the value of the "db" variable on line 38 of PendingTransactionRecovery.cs). I've double-checked my code and I don't have any duplicate ResourceManagerIds defined.
I also examined the MSDTC logs on my machine and found that the same GUID was attempting to be registered twice as two different resource managers. This led me to examine the ConfigureRavenPersistence class to see if its possible that we are creating multiple instances of a DocumentStore with the same ResourceManagerId.
If I put a breakpoint on line 54 of ConfigureRavenPersistence.cs (on the 3.3.0 branch), I can see that we are in fact instantiating & initializing multiple document stores with the same ResourceManagerId during the startup of an endpoint.
It looks like there could be a threading issue in the RavenPersistence method on ConfigureRavenPersistence. In my code, I am explicitly calling RavenSagaPersister() and RavenSubscriptionStorage() in the IConfigureThisEndpoint.Init() method. Both of these methods check to see if we already have an IDocumentStore configured, and if not, they will call ConfigureRavenPersistence.RavenPersistence(). I also see that the ProductionProfileHandler is explicitly calling ConfigureRavenPersistence.RavenPersistence(), but it does not first check to see whether an IDocumentStore has already been configured.
If it were possible to have IConfigureThisEndpoint.Init() and IHandleProfile.ProfileActivated() running side-by-side in different threads, then it would explain how we are getting multiple document stores created for a single endpoint.
Dan,
Thanks a lot for the detailed answer, I'll have a look at this today and see what is going on.
On Thursday, November 22, 2012, Dan Bishop wrote:
I've been doing some debugging on this issue, and the root cause of the problem is that RavenDB is encountering this error while starting up an endpoint:
A resource manager with the same identifier is already registered with the specified transaction coordinator
It is the NServiceBus database where RavenDB is encountering this error (this is visible by checking the value of the "db" variable on line 38 of PendingTransactionRecovery.cs). I've double-checked my code and I don't have any duplicate ResourceManagerIds defined.
I also examined the MSDTC logs on my machine and found that the same GUID was attempting to be registered twice as two different resource managers. This led me to examine the ConfigureRavenPersistence class to see if its possible that we are creating multiple instances of a DocumentStore with the same ResourceManagerId.
If I put a breakpoint on line 54 of ConfigureRavenPersistence.cs (on the 3.3.0 branch), I can see that we are in fact instantiating & initializing multiple document stores with the same ResourceManagerId during the startup of an endpoint.
It looks like there could be a threading issue in the RavenPersistence method on ConfigureRavenPersistence. In my code, I am explicitly calling RavenSagaPersister() and RavenSubscriptionStorage() in the IConfigureThisEndpoint.Init() method. Both of these methods check to see if we already have an IDocumentStore configured, and if not, they will call ConfigureRavenPersistence.RavenPersistence(). I also see that the ProductionProfileHandler is explicitly calling ConfigureRavenPersistence.RavenPersistence(), but it does not first check to see whether an IDocumentStore has already been configured.
If it were possible to have IConfigureThisEndpoint.Init() and IHandleProfile.ProfileActivated() running side-by-side in different threads, then it would explain how we are getting multiple document stores created for a single endpoint.
— Reply to this email directly or view it on GitHubhttps://github.com/NServiceBus/NServiceBus/issues/757#issuecomment-10613263.
Regards John Simons NServiceBus
You'd know this better than me, but it looks like the IHandleProfile.ProfileActivated() is being called after the IConfigureThisEndpoint.Init() method. Since the code in the ProductionProfileHandler is not first checking to see if there is an existing IDocumentStore configured, it is leading to this problem.
I am going to try removing my explicit calls to RavenSagaPersister() and RavenSubscriptionStorage() from my Init() method to see if that alleviates the problem.
After removing the calls to RavenSagaPersister() and RavenSubscriptionStorage(), things appear to be working for me. I still believe that a fix should be made in NServiceBus, as there is nothing to prevent someone from getting into this scenario.
I am still experiencing an issue where I have one pending RavenDB transaction on my machine, and when I startup multiple NServiceBus endpoints, it looks as though each DocumentStore instance is attempting to recover the pending transaction. Once the transaction is "recovered" by each of the DocumentStores, the logic in the RavenDB client attempts to delete the *.recovery-information file from disk. However, the delete is always failing because the *.recovery-information file is currently locked by each of the other NServiceBus host processes. I saw Oren's changeset that adds automatic retries to the deletion of the *.recovery-information files, but I have a feeling that adding the retries won't fix the problem.
I'm still happy to try an updated build out on my machine whenever its ready.
Ok, we'll fix that for 3.4.0, since it's no longer a blocking issue right?
On Thu, Nov 22, 2012 at 2:52 PM, Dan Bishop [email protected]:
After removing the calls to RavenSagaPersister() and RavenSubscriptionStorage(), things appear to be working for me. I still believe that a fix should be made in NServiceBus, as there is nothing to prevent someone from getting into this scenario.
I am still experiencing an issue where I have one pending RavenDB transaction on my machine, and when I startup multiple NServiceBus endpoints, it looks as though each DocumentStore instance is attempting to recover the pending transaction. Once the transaction is "recovered" by each of the DocumentStores, the logic in the RavenDB client attempts to delete the *.recovery-information file from disk. However, the delete is always failing because the *.recovery-information file is currently locked by each of the other NServiceBus host processes. I saw Oren's changeset that adds automatic retries to the deletion of the *.recovery-information files, but I have a feeling that adding the retries won't fix the problem.
I'm still happy to try an updated build out on my machine whenever its ready.
— Reply to this email directly or view it on GitHubhttps://github.com/NServiceBus/NServiceBus/issues/757#issuecomment-10635036.
http://andreasohlund.net http://twitter.com/andreasohlund
The issue of creating multiple DocumentStores is not blocking me anymore, no.
I believe there could be a significant issue with the pending transaction recovery in RavenDB 1.0.980. My experience locally is that having a single pending transaction that originated in the DocumentStore created by NServiceBus for Handler1 can cause all of my other NSB handlers to explode during startup. Its entirely possible that this is only an issue when performing a simultaneous startup of endpoints. If we could confirm that, then I think the severity would be lower.
Looking at the Raven code + the fix from oren it seems like it would only lock if more than one endpoint tries to startup at the same time so in the case of a single endpoint crashing we're fine
A server reboot on the other hand would cause multiple endpoints to startup at them same time. But given that windows services will retry if they fail to start it might be fine
On Thu, Nov 22, 2012 at 3:04 PM, Dan Bishop [email protected]:
The issue of creating multiple DocumentStores is not blocking me anymore, no.
I believe there could be a significant issue with the pending transaction recovery in RavenDB 1.0.980. My experience locally is that having a single pending transaction that originated in the DocumentStore created by NServiceBus for Handler1 can cause all of my other NSB handlers to explode during startup. Its entirely possible that this is only an issue when performing a simultaneous startup of endpoints. If we could confirm that, then I think the severity would be lower.
— Reply to this email directly or view it on GitHubhttps://github.com/NServiceBus/NServiceBus/issues/757#issuecomment-10635355.
http://andreasohlund.net http://twitter.com/andreasohlund
I ran into this with the latest version yesterday. Pretty annoying bug. I then had to switch back to 3.2.8 in order to give my presentation. Thanks for working on that!
Ehh I still think this is a very real blocking issue! I'm seeing the exact same thing.
Multiple endpoints starting up at the same time is a very normal use case. Like right after a deployment of several services.
Basically I'm left now with this choice:
- v3.3.2 and get this error, because we most certainly don't control the startup order of multiple endpoints on multiple servers.
- v3.2.8 and not beeing able to use multiple worker threads for Raven saga storage.
Not a great situation!
Edited: Removed that whiny little bitch part.. I was frustrated.. :)
Regards, Jan Ove
I'm seeing the exact same error Bishbulb reported and when a a endpoint gets this error, it doesn't come up anymore. Restaring the endpoint and/or RavenDB doesn't help. I'm guessing from the error message that the raven client code on the endpoint has some kind of state in the isolated storage. I'll try to nuke the storage tomorrow to check if that helps.
@janovesk @Bishbulb I've created a unstable 3.3.3 build with the proposed fix from Oren. Can you guys test it and see if it solves the issue?
Fix from Oren: https://github.com/ayende/ravendb/commit/9bc3fd31ed6623d5e43e5dafd0f7c4313b7e12c1 Binaries: http://builds.nservicebus.com/viewLog.html?buildId=627&buildTypeId=bt19&tab=artifacts OR https://nuget.org/packages/NServiceBus/3.3.3-unstable1