Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing concurrency handling when we are disposed.

  • Loading branch information...
commit 2b514344ecf3b279d5dda3469320cc50a790cec3 1 parent 4a66860
Ayende Rahien ayende authored
29 Raven.Storage.Esent/TransactionalStorage.cs
View
@@ -327,23 +327,27 @@ private bool EnsureDatabaseIsCreatedAndAttachToDatabase()
[DebuggerHidden, DebuggerNonUserCode, DebuggerStepThrough]
public void Batch(Action<IStorageActionsAccessor> action)
{
- if (disposed)
- {
- Trace.WriteLine("TransactionalStorage.Batch was called after it was disposed, call was ignored.");
- return; // this may happen if someone is calling us from the finalizer thread, so we can't even throw on that
- }
- if (current.Value != null)
- {
- action(current.Value);
- return;
- }
+ if (disposerLock.IsReadLockHeld) // we are currently in a nested Batch call
+ {
+ if (current.Value != null) // check again, just to be sure
+ {
+ action(current.Value);
+ return;
+ }
+ }
disposerLock.EnterReadLock();
try
{
ExecuteBatch(action);
}
catch (EsentErrorException e)
- {
+ {
+ if (disposed)
+ {
+ Trace.WriteLine("TransactionalStorage.Batch was called after it was disposed, call was ignored.");
+ return; // this may happen if someone is calling us from the finalizer thread, so we can't even throw on that
+ }
+
switch (e.Error)
{
case JET_err.WriteConflict:
@@ -357,7 +361,8 @@ public void Batch(Action<IStorageActionsAccessor> action)
finally
{
disposerLock.ExitReadLock();
- current.Value = null;
+ if(disposed == false)
+ current.Value = null;
}
}
26 Raven.Storage.Managed/TransactionalStorage.cs
View
@@ -86,20 +86,23 @@ public Guid Id
[DebuggerNonUserCode]
public void Batch(Action<IStorageActionsAccessor> action)
{
- if (disposed)
+ if (disposerLock.IsReadLockHeld) // we are currently in a nested Batch call
{
- Trace.WriteLine("TransactionalStorage.Batch was called after it was disposed, call was ignored.");
- return; // this may happen if someone is calling us from the finalizer thread, so we can't even throw on that
+ if (current.Value != null) // check again, just to be sure
+ {
+ action(current.Value);
+ return;
+ }
}
-
- if(current.Value != null)
- {
- action(current.Value);
- return;
- }
- disposerLock.EnterReadLock();
+ disposerLock.EnterReadLock();
try
{
+ if (disposed)
+ {
+ Trace.WriteLine("TransactionalStorage.Batch was called after it was disposed, call was ignored.");
+ return; // this may happen if someone is calling us from the finalizer thread, so we can't even throw on that
+ }
+
Interlocked.Exchange(ref lastUsageTime, SystemTime.Now.ToBinary());
using (tableStroage.BeginTransaction())
@@ -115,7 +118,8 @@ public void Batch(Action<IStorageActionsAccessor> action)
finally
{
disposerLock.ExitReadLock();
- current.Value = null;
+ if(disposed ==false)
+ current.Value = null;
}
}
2  Raven.Tryouts/Program.cs
View
@@ -1,4 +1,6 @@
using System;
+using Raven.Client.Listeners;
+using Raven.Json.Linq;
using Raven.Tests.Bugs;
namespace Raven.Tryouts
Please sign in to comment.
Something went wrong with that request. Please try again.