Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Properly handling disposal of the document database for replication s…

…cenarios
  • Loading branch information...
commit 1621dc82b35efbec463f3e72e63c53f04412471d 1 parent 97a8f23
Ayende Rahien authored August 18, 2011
7  Bundles/Raven.Bundles.Replication/Tasks/ReplicationTask.cs
@@ -95,6 +95,11 @@ private void Execute()
95 95
                                 Task.Factory.StartNew(() => ReplicateTo(destination), TaskCreationOptions.LongRunning)
96 96
                                     .ContinueWith(completedTask =>
97 97
                                     {
  98
+                                        if (completedTask.Exception != null)
  99
+                                        {
  100
+                                            log.ErrorException("Could not replicate to " + destination, completedTask.Exception);
  101
+                                            return;
  102
+                                        }
98 103
                                         if (completedTask.Result) // force re-evaluation of replication again
99 104
                                             docDb.WorkContext.NotifyAboutWork();
100 105
                                     });
@@ -164,6 +169,8 @@ private bool ReplicateTo(RavenConnectionStringOptions destination)
164 169
         {
165 170
             try
166 171
             {
  172
+                if (docDb.Disposed)
  173
+                    return false;
167 174
                 using (docDb.DisableAllTriggersForCurrentThread())
168 175
                 {
169 176
                     SourceReplicationInformation sourceReplicationInformation;
18  Raven.Database/DocumentDatabase.cs
@@ -264,6 +264,9 @@ public InMemoryRavenConfiguration Configuration
264 264
 
265 265
 		public void Dispose()
266 266
 		{
  267
+            if (disposed)
  268
+                return;
  269
+		    disposed = true;
267 270
 			workContext.StopWork();
268 271
 			foreach (var value in ExtensionsState.Values.OfType<IDisposable>())
269 272
 			{
@@ -1164,8 +1167,9 @@ public static string BuildVersion
1164 1167
 		}
1165 1168
 
1166 1169
 		static string productVersion;
  1170
+	    private volatile bool disposed;
1167 1171
 
1168  
-		public static string ProductVersion
  1172
+	    public static string ProductVersion
1169 1173
 		{
1170 1174
 			get
1171 1175
 			{
@@ -1191,12 +1195,22 @@ public string[] GetIndexFields(string index)
1191 1195
 		/// <returns></returns>
1192 1196
 		public IDisposable DisableAllTriggersForCurrentThread()
1193 1197
 		{
  1198
+            if (disposed)
  1199
+                return new DisposableAction(() => { });
1194 1200
 			var old = disableAllTriggers.Value;
1195 1201
 			disableAllTriggers.Value = true;
1196 1202
 			return new DisposableAction(() => disableAllTriggers.Value = old);
1197 1203
 		}
1198 1204
 
1199  
-		/// <summary>
  1205
+        /// <summary>
  1206
+        /// Whatever this database has been disposed
  1207
+        /// </summary>
  1208
+	    public bool Disposed
  1209
+	    {
  1210
+	        get { return disposed; }
  1211
+	    }
  1212
+
  1213
+	    /// <summary>
1200 1214
 		/// Get the total size taken by the database on the disk.
1201 1215
 		/// This explicitly does NOT include in memory indexes or in memory database.
1202 1216
 		/// It does include any reserved space on the file system, which may significantly increase

0 notes on commit 1621dc8

Please sign in to comment.
Something went wrong with that request. Please try again.